summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-03-20 11:25:39 -0700
committerPaul Phillips <paulp@improving.org>2012-03-20 18:41:04 -0700
commitb9e933ffca8108ed86c09a298a44636b714f7a19 (patch)
tree222ffe54dc72a2ee11b1b5f0e95e1ce182f16a61 /src
parentd8ba5d091e5641553b438ef9930a6023a2709dcd (diff)
downloadscala-b9e933ffca8108ed86c09a298a44636b714f7a19.tar.gz
scala-b9e933ffca8108ed86c09a298a44636b714f7a19.tar.bz2
scala-b9e933ffca8108ed86c09a298a44636b714f7a19.zip
Tweak to string coloring.
Concluded String->String would be more useful more often.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/ast/NodePrinters.scala15
-rw-r--r--src/compiler/scala/tools/util/color/CString.scala19
-rw-r--r--src/compiler/scala/tools/util/color/package.scala1
3 files changed, 22 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/NodePrinters.scala b/src/compiler/scala/tools/nsc/ast/NodePrinters.scala
index 3d4253f941..07e864879d 100644
--- a/src/compiler/scala/tools/nsc/ast/NodePrinters.scala
+++ b/src/compiler/scala/tools/nsc/ast/NodePrinters.scala
@@ -45,21 +45,20 @@ abstract class NodePrinters {
def flagColor = Red
def literalColor = Green
- override def showFlags(tree: MemberDef) = "" + (
+ override def showFlags(tree: MemberDef) =
super.showFlags(tree) in flagColor.bright
- )
- override def showDefTreeName(tree: DefTree) = "" + (
+
+ override def showDefTreeName(tree: DefTree) =
if (tree.name.isTermName) tree.name.decode in termColor.bright
else tree.name.decode in typeColor.bright
- )
- override def showName(name: Name): String = "" + (
+
+ override def showName(name: Name) =
if (name == nme.EMPTY || name == tpnme.EMPTY) "<empty>" in keywordColor
else if (name.isTermName) name.decode in termColor
else name.decode in typeColor
- )
- override def showLiteral(lit: Literal) = "" + (
+
+ override def showLiteral(lit: Literal) =
super.showLiteral(lit) in literalColor.bright
- )
}
trait DefaultPrintAST extends PrintAST {
diff --git a/src/compiler/scala/tools/util/color/CString.scala b/src/compiler/scala/tools/util/color/CString.scala
index d0785eaeff..fa57229f09 100644
--- a/src/compiler/scala/tools/util/color/CString.scala
+++ b/src/compiler/scala/tools/util/color/CString.scala
@@ -11,18 +11,27 @@ final class CString(val uncolorized: String, val colorized: String) {
def visibleLength = uncolorized.length
def colorizedLength = colorized.length
def show() = Console println colorized
- def bytes() = colorized map (ch => ch.toByte)
- def > = show()
+ def bytes() = colorized map (_.toByte)
+ def >() = show()
def append(x: CString): CString = new CString(uncolorized + x.uncolorized, colorized + x.colorized)
def +(other: CString): CString = this append other
+
override def toString = colorized
}
class CStringOps(str: String) {
- /** Enables for example
+ /** String to String operation.
* println("foo" in Red)
- * println("foo" in Magenta.bright)
+ * println("bar" in Magenta.bright)
+ */
+ def in(ansi: Ansi): String = ansi colorize str
+
+ /** Gave in to one bit of punctuation, because everyone adds
+ * strings with '+' and we need something which higher precedence
+ * for it to be at all satisfying.
+ *
+ * "foo" %> Red + "bar" %> Magenta.bright
*/
- def in(ansi: Ansi): CString = new CString(str, ansi colorize str)
+ def %>(ansi: Ansi): CString = new CString(str, in(ansi))
}
diff --git a/src/compiler/scala/tools/util/color/package.scala b/src/compiler/scala/tools/util/color/package.scala
index 7c7c7dab74..3b3e85751e 100644
--- a/src/compiler/scala/tools/util/color/package.scala
+++ b/src/compiler/scala/tools/util/color/package.scala
@@ -18,4 +18,5 @@ package object color {
case x: AnsiForeground => x.flip
}
implicit def implicitCStringOps(str: String): CStringOps = new CStringOps(str)
+ implicit def implicitCString(str: String): CString = new CString(str, str)
}