summaryrefslogtreecommitdiff
path: root/test/files/run/color.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-03-17 19:16:38 -0700
committerPaul Phillips <paulp@improving.org>2012-03-18 10:36:55 -0700
commit438ae4766ae5245884a004acbf465125c97813f5 (patch)
treef75fb994a944b7c6796f65f1e07522c2a0837dd5 /test/files/run/color.scala
parentd267988ddbf03c71fa1ef2fa51f2d218793632ed (diff)
downloadscala-438ae4766ae5245884a004acbf465125c97813f5.tar.gz
scala-438ae4766ae5245884a004acbf465125c97813f5.tar.bz2
scala-438ae4766ae5245884a004acbf465125c97813f5.zip
Library for ansi color management.
Having now experienced the unbelievable difference it makes to have one's voluminous debugging output effectively color-coded, I had to librarize the ansi codes in order to use them. This could all go in the standard library, or as soon as I can easily make use of compiler dependencies, a separate library altogether. For now it hides away in scala.tools.util.color.
Diffstat (limited to 'test/files/run/color.scala')
-rw-r--r--test/files/run/color.scala33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/files/run/color.scala b/test/files/run/color.scala
new file mode 100644
index 0000000000..a0af8477e7
--- /dev/null
+++ b/test/files/run/color.scala
@@ -0,0 +1,33 @@
+import scala.tools.util.color._
+
+object Test {
+ // The ones which are somewhat widely supported.
+ def effects = List(Bright, Underline, Inverse)
+
+ def demo(text: String) = {
+ def to_s(esc: Ansi): String = esc.atoms map {
+ case x: AnsiBackground => "" + x
+ case x => "%-10s" format x
+ } mkString " "
+
+ def show(esc: Ansi) = println("%s %s".format(text in esc, to_s(esc)))
+
+ println("\n1 color")
+ for (c <- Ansi.colors) show(c)
+ println("\n1 effect")
+ for (e <- Ansi.effects) show(e)
+ println("\n1 color 1 effect")
+ for (c <- Ansi.colors; e <- effects) show(c / e)
+ println("\n2 colors 0 effects")
+ for (c1 <- Ansi.colors ; c2 <- Ansi.colors) show(c2 on c1)
+ println("\n2 colors 1 effect")
+ for (c1 <- Ansi.colors ; c2 <- Ansi.colors ; e1 <- effects) show((c2 on c1) / e1)
+ println("\n2 colors 2 effects")
+ for (c1 <- Ansi.colors ; c2 <- Ansi.colors ; e1 <- effects ; e2 <- effects ; if e1 != e2) show((c2 on c1) / e1 / e2)
+ }
+
+ def main(args: Array[String]): Unit = {
+ val str = if (args.size > 1) args mkString " " else "the quick brown fox"
+ demo(str)
+ }
+}