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/reporting | |
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/reporting')
-rw-r--r-- | src/dotty/tools/dotc/reporting/ConsoleReporter.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/reporting/FancyConsoleReporter.scala | 55 | ||||
-rw-r--r-- | src/dotty/tools/dotc/reporting/Reporter.scala | 2 |
3 files changed, 29 insertions, 30 deletions
diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala index b532d05c2..1ae6a1135 100644 --- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala +++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala @@ -44,7 +44,7 @@ class ConsoleReporter( } } - def printExplanation(m: Message): Unit = + def printExplanation(m: Message)(implicit ctx: Context): Unit = printMessage( s"""| |Explanation diff --git a/src/dotty/tools/dotc/reporting/FancyConsoleReporter.scala b/src/dotty/tools/dotc/reporting/FancyConsoleReporter.scala index 3fc9ab473..d69396f5f 100644 --- a/src/dotty/tools/dotc/reporting/FancyConsoleReporter.scala +++ b/src/dotty/tools/dotc/reporting/FancyConsoleReporter.scala @@ -21,29 +21,29 @@ class FancyConsoleReporter( writer: PrintWriter = new PrintWriter(Console.err, true) ) extends ConsoleReporter(reader, writer) { + def stripColor(str: String): String = + str.replaceAll("\u001B\\[[;\\d]*m", "") + def sourceLine(pos: SourcePosition)(implicit ctx: Context): (String, Int) = { val lineNum = s"${pos.line}:" (lineNum + hl"${pos.lineContent.stripLineEnd}", lineNum.length) } - def columnMarker(pos: SourcePosition, offset: Int) = + def columnMarker(pos: SourcePosition, offset: Int)(implicit ctx: Context) = if (pos.startLine == pos.endLine) { val whitespace = " " * (pos.column + offset) val carets = - AnnotationColor + - ("^" * math.max(1, pos.endColumn - pos.startColumn)) + - NoColor + Red("^" * math.max(1, pos.endColumn - pos.startColumn)) - whitespace + carets + whitespace + carets.show } else { - " " * (pos.column + offset) + AnnotationColor + "^" + NoColor + Red(" " * (pos.column + offset) + "^").show } def errorMsg(pos: SourcePosition, msg: String, offset: Int)(implicit ctx: Context) = { var hasLongLines = false val leastWhitespace = msg.lines.foldLeft(Int.MaxValue) { (minPad, line) => - val lineLength = - line.replaceAll("\u001B\\[[;\\d]*m", "").length + val lineLength = stripColor(line).length val padding = math.min(math.max(0, ctx.settings.pageWidth.value - offset - lineLength), offset + pos.startColumn) @@ -68,9 +68,9 @@ class FancyConsoleReporter( val prefix = s"-- $kind: $file " prefix + - ("-" * math.max(ctx.settings.pageWidth.value - prefix.replaceAll("\u001B\\[[;\\d]*m", "").length, 0)) + + ("-" * math.max(ctx.settings.pageWidth.value - stripColor(prefix).length, 0)) + "\n" + outer - }).toString else "" + }).show else "" /** Prints the message with the given position indication. */ override def printMessageAndPos(msg: String, pos: SourcePosition, kind: String = "")(implicit ctx: Context): Unit = { @@ -84,23 +84,22 @@ class FancyConsoleReporter( } else printMessage(msg) } - override def printExplanation(m: Message): Unit = - printMessage( - s"""| - |${Blue("Explanation")} - |${Blue("===========")} - |${m.explanation}""".stripMargin - ) - - - override def summary: String = { - val b = new mutable.ListBuffer[String] - if (warningCount > 0) - b += countString(warningCount, Yellow("warning")) + " found" - if (errorCount > 0) - b += countString(errorCount, Red("error")) + " found" - for ((settingName, count) <- unreportedWarnings) - b += s"there were $count ${settingName.tail} ${Yellow("warning(s)")}; re-run with $settingName for details" - b.mkString("\n") + override def printExplanation(m: Message)(implicit ctx: Context): Unit = { + printMessage(hl"""| + |${Blue("Explanation")} + |${Blue("===========")}""".stripMargin) + printMessage(m.explanation) } + + + //override def summary(implicit ctx: Context): String = { + // val b = new mutable.ListBuffer[String] + // if (warningCount > 0) + // b += countString(warningCount, Yellow("warning").show) + " found" + // if (errorCount > 0) + // b += countString(errorCount, Red("error").show) + " found" + // for ((settingName, count) <- unreportedWarnings) + // b += s"there were $count ${settingName.tail} ${Yellow("warning(s)").show}; re-run with $settingName for details" + // b.mkString("\n") + //} } diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala index fe226b284..538464daa 100644 --- a/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/src/dotty/tools/dotc/reporting/Reporter.scala @@ -247,7 +247,7 @@ abstract class Reporter extends interfaces.ReporterResult { /** Summary of warnings and errors */ - def summary: String = { + def summary/*(implicit ctx: Context)*/: String = { val b = new mutable.ListBuffer[String] if (warningCount > 0) b += countString(warningCount, "warning") + " found" |