diff options
Diffstat (limited to 'src/dotty/tools/dotc/reporting/FancyConsoleReporter.scala')
-rw-r--r-- | src/dotty/tools/dotc/reporting/FancyConsoleReporter.scala | 55 |
1 files changed, 27 insertions, 28 deletions
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") + //} } |