summaryrefslogtreecommitdiff
path: root/src/partest-alternative/scala/tools/partest/io/ANSIWriter.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/partest-alternative/scala/tools/partest/io/ANSIWriter.scala')
-rw-r--r--src/partest-alternative/scala/tools/partest/io/ANSIWriter.scala58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/partest-alternative/scala/tools/partest/io/ANSIWriter.scala b/src/partest-alternative/scala/tools/partest/io/ANSIWriter.scala
new file mode 100644
index 0000000000..0ddcd97a5f
--- /dev/null
+++ b/src/partest-alternative/scala/tools/partest/io/ANSIWriter.scala
@@ -0,0 +1,58 @@
+/* NEST (New Scala Test)
+ * Copyright 2007-2010 LAMP/EPFL
+ * @author Philipp Haller
+ */
+
+package scala.tools
+package partest
+package io
+
+import java.io.{ Writer, PrintWriter, OutputStream, OutputStreamWriter }
+
+object ANSIWriter {
+ val NONE = 0
+ val SOME = 1
+ val MANY = 2
+
+ def apply(isAnsi: Boolean) = if (isAnsi) MANY else NONE
+}
+import ANSIWriter._
+
+class ANSIWriter(writer: Writer) extends PrintWriter(writer, true) {
+ def this(out: OutputStream) = this(new OutputStreamWriter(out))
+ def colorful: Int = NONE
+
+ protected val manyColors = List(
+ Console.BOLD + Console.BLACK,
+ Console.BOLD + Console.GREEN,
+ Console.BOLD + Console.RED,
+ Console.BOLD + Console.YELLOW,
+ Console.RESET
+ )
+ protected val someColors = List(
+ Console.BOLD + Console.BLACK,
+ Console.RESET,
+ Console.BOLD + Console.BLACK,
+ Console.BOLD + Console.BLACK,
+ Console.RESET
+ )
+ protected val noColors = List("", "", "", "", "")
+
+ lazy val List(_outline, _success, _failure, _warning, _default) = colorful match {
+ case NONE => noColors
+ case SOME => someColors
+ case MANY => manyColors
+ case _ => noColors
+ }
+
+ private def wrprint(msg: String): Unit = synchronized {
+ print(msg)
+ flush()
+ }
+
+ def outline(msg: String) = wrprint(_outline + msg + _default)
+ def success(msg: String) = wrprint(_success + msg + _default)
+ def failure(msg: String) = wrprint(_failure + msg + _default)
+ def warning(msg: String) = wrprint(_warning + msg + _default)
+ def normal(msg: String) = wrprint(_default + msg)
+}