diff options
author | Paul Phillips <paulp@improving.org> | 2012-03-20 11:25:39 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-03-20 18:41:04 -0700 |
commit | b9e933ffca8108ed86c09a298a44636b714f7a19 (patch) | |
tree | 222ffe54dc72a2ee11b1b5f0e95e1ce182f16a61 /src/compiler/scala/tools/util | |
parent | d8ba5d091e5641553b438ef9930a6023a2709dcd (diff) | |
download | scala-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/compiler/scala/tools/util')
-rw-r--r-- | src/compiler/scala/tools/util/color/CString.scala | 19 | ||||
-rw-r--r-- | src/compiler/scala/tools/util/color/package.scala | 1 |
2 files changed, 15 insertions, 5 deletions
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) } |