Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created July 13, 2011 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugyo/1080509 to your computer and use it in GitHub Desktop.
Save jugyo/1080509 to your computer and use it in GitHub Desktop.
scala-swing-repl
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment