summaryrefslogtreecommitdiff
path: root/src/repl
diff options
context:
space:
mode:
authorBrian McKenna <brian@simpleenergy.com>2014-09-21 21:56:56 -0600
committerBrian McKenna <brian@simpleenergy.com>2014-09-21 22:05:46 -0600
commit9902ae5eca9ae52410231d42a8c96df9454034f4 (patch)
tree936496027d463a50fccd0250ab4d95ca05d6b306 /src/repl
parent379dbb0f6aa1d2d1233771a2dccec6c2dc584222 (diff)
downloadscala-9902ae5eca9ae52410231d42a8c96df9454034f4.tar.gz
scala-9902ae5eca9ae52410231d42a8c96df9454034f4.tar.bz2
scala-9902ae5eca9ae52410231d42a8c96df9454034f4.zip
Color REPL under -Dscala.color
We already use -Dscala.color when using -Ytyper-debug This tries to reuse the colors chosen from the debug flag: * Bold blue for vals (e.g. "res0") * Bold green for types (e.g. "Int") * Magenta for the shell prompt (e.g. "scala>")
Diffstat (limited to 'src/repl')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala8
-rw-r--r--src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala10
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ReplProps.scala3
3 files changed, 19 insertions, 2 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
index 50c89f7442..cfc4e5a5c8 100644
--- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
@@ -445,8 +445,14 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
private def readOneLine() = {
+ import scala.io.AnsiColor.{ MAGENTA, RESET }
out.flush()
- in readLine prompt
+ in readLine (
+ if (replProps.colorOk)
+ MAGENTA + prompt + RESET
+ else
+ prompt
+ )
}
/** The main read-eval-print loop for the repl. It calls
diff --git a/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala b/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
index a37cdc2ec8..8e624174ed 100644
--- a/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
+++ b/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
@@ -119,7 +119,15 @@ trait MemberHandlers {
if (replProps.vids) s"""" + f"@$${System.identityHashCode($path)}%8x" + """"
else ""
- """ + "%s%s: %s = " + %s""".format(string2code(prettyName), vidString, string2code(req typeOf name), resultString)
+ import scala.io.AnsiColor.{ BOLD, BLUE, GREEN, RESET }
+
+ def color(c: String, s: String) =
+ if (replProps.colorOk) string2code(BOLD) + string2code(c) + s + string2code(RESET)
+ else s
+
+ val nameString = color(BLUE, string2code(prettyName)) + vidString
+ val typeString = color(GREEN, string2code(req typeOf name))
+ s""" + "$nameString: $typeString = " + $resultString"""
}
}
}
diff --git a/src/repl/scala/tools/nsc/interpreter/ReplProps.scala b/src/repl/scala/tools/nsc/interpreter/ReplProps.scala
index 36e6dbbccc..8c4faf7278 100644
--- a/src/repl/scala/tools/nsc/interpreter/ReplProps.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ReplProps.scala
@@ -13,6 +13,9 @@ class ReplProps {
private def bool(name: String) = BooleanProp.keyExists(name)
private def int(name: String) = IntProp(name)
+ // This property is used in TypeDebugging. Let's recycle it.
+ val colorOk = bool("scala.color")
+
val info = bool("scala.repl.info")
val debug = bool("scala.repl.debug")
val trace = bool("scala.repl.trace")