Skip to content

Commit 8a560a2

Browse files
committed
Add color to severity in REPL reporter
* Errors are red * Warnings are yellow
1 parent 9902ae5 commit 8a560a2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr
2929
case INFO => null
3030
}
3131

32-
private def clabel(severity: Severity): String = {
32+
protected def clabel(severity: Severity): String = {
3333
val label0 = label(severity)
3434
if (label0 eq null) "" else label0 + ": "
3535
}

src/repl/scala/tools/nsc/interpreter/ReplReporter.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ class ReplReporter(intp: IMain) extends ConsoleReporter(intp.settings, Console.i
3232
override def warning(pos: Position, msg: String): Unit = withoutTruncating(super.warning(pos, msg))
3333
override def error(pos: Position, msg: String): Unit = withoutTruncating(super.error(pos, msg))
3434

35+
import scala.io.AnsiColor.{ RED, YELLOW, RESET }
36+
37+
def severityColor(severity: Severity): String = severity match {
38+
case ERROR => RED
39+
case WARNING => YELLOW
40+
case INFO => RESET
41+
}
42+
43+
override def print(pos: Position, msg: String, severity: Severity) {
44+
val prefix = (
45+
if (replProps.colorOk)
46+
severityColor(severity) + clabel(severity) + RESET
47+
else
48+
clabel(severity)
49+
)
50+
printMessage(pos, prefix + msg)
51+
}
52+
3553
override def printMessage(msg: String) {
3654
// Avoiding deadlock if the compiler starts logging before
3755
// the lazy val is complete.

0 commit comments

Comments
 (0)