diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-09-18 08:45:29 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-10-10 13:25:34 +0200 |
commit | 628b7f317756ce2c366359a7399b8dda9d0190b7 (patch) | |
tree | da64dc5eb15095287272a616f43ad56afaba3763 /src/dotty/tools/dotc/printing | |
parent | 787a2ceec02fe07fbb9efee673d3abb7cac2969e (diff) | |
download | dotty-628b7f317756ce2c366359a7399b8dda9d0190b7.tar.gz dotty-628b7f317756ce2c366359a7399b8dda9d0190b7.tar.bz2 dotty-628b7f317756ce2c366359a7399b8dda9d0190b7.zip |
Make `FancyConsoleReporter` and `Highlighting` obey color setting
Fancy console reporter and the string interpolator for highlighting now
obey the color setting - this means that the next step towards unifying
the reporters is to make sure the tests work with
`FancyConsoleReporter` under the `-color:never` flag.
Diffstat (limited to 'src/dotty/tools/dotc/printing')
-rw-r--r-- | src/dotty/tools/dotc/printing/Highlighting.scala | 33 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/SyntaxHighlighting.scala | 13 |
2 files changed, 34 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/printing/Highlighting.scala b/src/dotty/tools/dotc/printing/Highlighting.scala index 75f83bf29..13e55722f 100644 --- a/src/dotty/tools/dotc/printing/Highlighting.scala +++ b/src/dotty/tools/dotc/printing/Highlighting.scala @@ -3,36 +3,47 @@ package dotc package printing import scala.collection.mutable +import core.Contexts.Context object Highlighting { - implicit def highlightToString(h: Highlight): String = h.toString - implicit def hbufToString(hb: HighlightBuffer): String = hb.toString + implicit def highlightShow(h: Highlight)(implicit ctx: Context): String = + h.show + implicit def highlightToString(h: Highlight): String = + h.toString + implicit def hbufToString(hb: HighlightBuffer): String = + hb.toString abstract class Highlight(private val highlight: String) { def text: String - override def toString = highlight + text + Console.RESET + def show(implicit ctx: Context) = + if (ctx.settings.color.value == "never") text + else highlight + text + Console.RESET - def +(other: Highlight): HighlightBuffer = + override def toString = + highlight + text + Console.RESET + + def +(other: Highlight)(implicit ctx: Context): HighlightBuffer = new HighlightBuffer(this) + other - def +(other: String): HighlightBuffer = + def +(other: String)(implicit ctx: Context): HighlightBuffer = new HighlightBuffer(this) + other } abstract class Modifier(private val mod: String, text: String) extends Highlight(Console.RESET) { - override def toString = - mod + super.toString + override def show(implicit ctx: Context) = + if (ctx.settings.color.value == "never") "" + else mod + super.show } - case class HighlightBuffer(hl: Highlight) { + case class HighlightBuffer(hl: Highlight)(implicit ctx: Context) { val buffer = new mutable.ListBuffer[String] - buffer += hl.toString + buffer += hl.show def +(other: Highlight): HighlightBuffer = { - buffer += other.toString + buffer += other.show this } @@ -45,6 +56,8 @@ object Highlighting { buffer.mkString } + case class NoColor(text: String) extends Highlight(Console.RESET) + case class Red(text: String) extends Highlight(Console.RED) case class Blue(text: String) extends Highlight(Console.BLUE) case class Cyan(text: String) extends Highlight(Console.CYAN) diff --git a/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala index d94f6796d..95e59ccf3 100644 --- a/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -6,14 +6,23 @@ import parsing.Tokens._ import scala.annotation.switch import scala.collection.mutable.StringBuilder import core.Contexts.Context +import Highlighting.{Highlight, HighlightBuffer} /** This object provides functions for syntax highlighting in the REPL */ object SyntaxHighlighting { implicit class SyntaxFormatting(val sc: StringContext) extends AnyVal { def hl(args: Any*)(implicit ctx: Context): String = - if (ctx.settings.color.value == "never") sc.s(args: _*) - else sc.s(args.map(x => new String(apply(x.toString).toArray)): _*) + sc.s(args.map ({ + case hl: Highlight => + hl.show + case hb: HighlightBuffer => + hb.toString + case x if ctx.settings.color.value != "never" => + new String(apply(x.toString).toArray) + case x => + x.toString + }): _*) } val NoColor = Console.RESET |