public
Created

scala-swing-repl

  • Download Gist
gistfile1.sbt
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
package test
 
import scala.swing._
import scala.tools.nsc._
import scala.tools.nsc.interpreter._
import java.awt.Dimension
import java.io.{OutputStream, PrintStream}
 
/**
* scala-compiler.jar is required
*
* TODO: key bind
* TODO: output with UTF-8
* TODO: monospace font
* TODO: support undo
* TODO: use ScrollPane
*/
object ScalaREPL extends SimpleSwingApplication {
val settings = new Settings
settings.usejavacp.value = true
val input = new TextArea
val output = new TextArea {
editable = false
}
val main = new IMain(settings)
 
System.setOut(new PrintStream(new OutputStream {
def write(b: Int) {
// multi byte is not supported
output.text += String.valueOf(b.toChar)
}
}, true))
 
def top = new MainFrame { frame =>
title = "Scala REPL"
 
contents = new SplitPane {
dividerLocation = 300
topComponent = input
bottomComponent = output
}
 
menuBar = new MenuBar {
contents += new Button(Action("Eval") {
main.interpret(input.text)
})
contents += new Button(Action("Clear") {
output.text = ""
})
}
 
size = new Dimension(500, 600)
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.