Skip to content

Commit

Permalink
Repl view: add support infrastructure for different text style for er…
Browse files Browse the repository at this point in the history
…rors vs. results. No change in behavior yet, since that requires a refactoring of IMain/ILoop on the compiler side.
  • Loading branch information
lindydonna committed Jun 21, 2011
1 parent 42eaf23 commit 65a134f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Expand Up @@ -50,10 +50,11 @@ class EclipseRepl(project: ScalaProject, settings: Settings, replView: ReplConso
private val eventQueue = actor {
loop { receive {
case code: String =>
Console.withOut(ViewOutputStream) {
intp interpret code
val output = new ViewOutputStream(false)
Console.withOut(output) {
intp.interpret(code)
}
ViewOutputStream.flush
output.flush
}}
}

Expand All @@ -65,7 +66,7 @@ class EclipseRepl(project: ScalaProject, settings: Settings, replView: ReplConso

var intp = createCompiler()

private def createCompiler(): IMain = new IMain(settings, new PrintWriter(ViewOutputStream))
private def createCompiler(): IMain = new IMain(settings, new PrintWriter(new ViewOutputStream(false)))
private def resetCompiler = {
intp.close
intp = createCompiler()
Expand All @@ -85,10 +86,14 @@ class EclipseRepl(project: ScalaProject, settings: Settings, replView: ReplConso
replayList foreach { addToQueue(_) }
}

object ViewOutputStream extends java.io.ByteArrayOutputStream { self =>
class ViewOutputStream(isErrorStream: Boolean) extends java.io.ByteArrayOutputStream { self =>
override def flush() {
SWTUtils.asyncExec {
replView displayOutput self.toString
if (isErrorStream)
replView displayError self.toString
else
replView displayOutput self.toString

self.reset
}
}
Expand Down
Expand Up @@ -30,6 +30,8 @@ class ReplConsoleView extends ViewPart {
var textWidget: StyledText = null
var codeBgColor: Color = null
var codeFgColor: Color = null
var errorFgColor: Color = null

var projectName: String = ""
private var scalaProject: ScalaProject = null
var isStopped = true
Expand Down Expand Up @@ -124,8 +126,9 @@ class ReplConsoleView extends ViewPart {
projectName = getViewSite.getSecondaryId
if (projectName == null) projectName = ""

codeBgColor = new Color(parent.getDisplay, 230, 230, 230) // light gray
codeFgColor = new Color(parent.getDisplay, 64, 0, 128) // eggplant
codeBgColor = new Color(parent.getDisplay, 230, 230, 230) // light gray
codeFgColor = new Color(parent.getDisplay, 64, 0, 128) // eggplant
errorFgColor = new Color(parent.getDisplay, 128, 0, 64) // maroon

val panel = new Composite(parent, SWT.NONE)
panel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true))
Expand Down Expand Up @@ -165,6 +168,10 @@ class ReplConsoleView extends ViewPart {
appendText(text, null, null, SWT.NORMAL)
}

def displayError(text: String) {
appendText(text, errorFgColor, null, SWT.NORMAL)
}

private def appendText(text: String, fgColor: Color, bgColor: Color, fontStyle: Int, insertNewline: Boolean = false) {
val lastOffset = textWidget.getCharCount
val oldLastLine = textWidget.getLineCount
Expand All @@ -187,6 +194,7 @@ class ReplConsoleView extends ViewPart {
override def dispose() {
codeBgColor.dispose
codeFgColor.dispose
errorFgColor.dispose

if (!isStopped)
EclipseRepl.stopRepl(scalaProject, flush = false)
Expand Down

0 comments on commit 65a134f

Please sign in to comment.