summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-03-19 16:14:58 -0700
committerPaul Phillips <paulp@improving.org>2012-03-19 16:41:17 -0700
commitaafcc104b6ebe2fa163fc7a9cbfb742bf5f26d08 (patch)
treeff54fac219e9e1218bc4cd233b7e8370a35c66f8
parent752884f1606320913ffe66f3bbf3db61746e2436 (diff)
downloadscala-aafcc104b6ebe2fa163fc7a9cbfb742bf5f26d08.tar.gz
scala-aafcc104b6ebe2fa163fc7a9cbfb742bf5f26d08.tar.bz2
scala-aafcc104b6ebe2fa163fc7a9cbfb742bf5f26d08.zip
Chill out repl ctrl-char filter.
So colors can come through unscathed.
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Naming.scala20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/Naming.scala b/src/compiler/scala/tools/nsc/interpreter/Naming.scala
index 8e215cf63b..19266442cb 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Naming.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Naming.scala
@@ -11,16 +11,18 @@ package interpreter
*/
trait Naming {
def unmangle(str: String): String = {
+ val ESC = '\u001b'
val cleaned = removeIWPackages(removeLineWrapper(str))
- var ctrlChars = 0
- cleaned map { ch =>
- if (ch.isControl && !ch.isWhitespace) {
- ctrlChars += 1
- if (ctrlChars > 5) return "[line elided for control chars: possibly a scala signature]"
- else '?'
- }
- else ch
- }
+ // Looking to exclude binary data which hoses the terminal, but
+ // let through the subset of it we need, like whitespace and also
+ // <ESC> for ansi codes.
+ val binaryChars = cleaned count (ch => ch < 32 && !ch.isWhitespace && ch != ESC)
+ // Lots of binary chars - translate all supposed whitespace into spaces
+ if (binaryChars > 5)
+ cleaned map (ch => if (ch.isWhitespace) ' ' else if (ch < 32) '?' else ch)
+ // Not lots - preserve whitespace and ESC
+ else
+ cleaned map (ch => if (ch.isWhitespace || ch == ESC) ch else if (ch < 32) '?' else ch)
}
// The two name forms this is catching are the two sides of this assignment: