Created
July 13, 2011 15:22
-
-
Save jugyo/1080509 to your computer and use it in GitHub Desktop.
scala-swing-repl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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