@@ -21,29 +21,29 @@ class FancyConsoleReporter(
21
21
writer : PrintWriter = new PrintWriter (Console .err, true )
22
22
) extends ConsoleReporter (reader, writer) {
23
23
24
+ def stripColor (str : String ): String =
25
+ str.replaceAll(" \u001B\\ [[;\\ d]*m" , " " )
26
+
24
27
def sourceLine (pos : SourcePosition )(implicit ctx : Context ): (String , Int ) = {
25
28
val lineNum = s " ${pos.line}: "
26
29
(lineNum + hl " ${pos.lineContent.stripLineEnd}" , lineNum.length)
27
30
}
28
31
29
- def columnMarker (pos : SourcePosition , offset : Int ) =
32
+ def columnMarker (pos : SourcePosition , offset : Int )( implicit ctx : Context ) =
30
33
if (pos.startLine == pos.endLine) {
31
34
val whitespace = " " * (pos.column + offset)
32
35
val carets =
33
- AnnotationColor +
34
- (" ^" * math.max(1 , pos.endColumn - pos.startColumn)) +
35
- NoColor
36
+ Red (" ^" * math.max(1 , pos.endColumn - pos.startColumn))
36
37
37
- whitespace + carets
38
+ whitespace + carets.show
38
39
} else {
39
- " " * (pos.column + offset) + AnnotationColor + " ^" + NoColor
40
+ Red ( " " * (pos.column + offset) + " ^" ).show
40
41
}
41
42
42
43
def errorMsg (pos : SourcePosition , msg : String , offset : Int )(implicit ctx : Context ) = {
43
44
var hasLongLines = false
44
45
val leastWhitespace = msg.lines.foldLeft(Int .MaxValue ) { (minPad, line) =>
45
- val lineLength =
46
- line.replaceAll(" \u001B\\ [[;\\ d]*m" , " " ).length
46
+ val lineLength = stripColor(line).length
47
47
val padding =
48
48
math.min(math.max(0 , ctx.settings.pageWidth.value - offset - lineLength), offset + pos.startColumn)
49
49
@@ -60,11 +60,10 @@ class FancyConsoleReporter(
60
60
def posStr (pos : SourcePosition , kind : String )(implicit ctx : Context ) =
61
61
if (pos.exists) Blue ({
62
62
val file = pos.source.file.toString
63
-
64
63
val prefix = s " -- $kind: $file "
65
64
prefix +
66
- (" -" * math.max(ctx.settings.pageWidth.value - prefix.replaceAll( " \u001B\\ [[; \\ d]*m " , " " ).length, 0 ))
67
- }).toString else " "
65
+ (" -" * math.max(ctx.settings.pageWidth.value - stripColor(prefix ).length, 0 ))
66
+ }).show else " "
68
67
69
68
/** Prints the message with the given position indication. */
70
69
override def printMessageAndPos (msg : String , pos : SourcePosition , kind : String = " " )(implicit ctx : Context ): Unit = {
@@ -78,23 +77,22 @@ class FancyConsoleReporter(
78
77
} else printMessage(msg)
79
78
}
80
79
81
- override def printExplanation (m : Message ): Unit =
82
- printMessage(
83
- s """ |
84
- | ${Blue (" Explanation" )}
85
- | ${Blue (" ===========" )}
86
- | ${m.explanation}""" .stripMargin
87
- )
80
+ override def printExplanation (m : Message )(implicit ctx : Context ): Unit = {
81
+ printMessage(hl """ |
82
+ | ${Blue (" Explanation" )}
83
+ | ${Blue (" ===========" )}""" .stripMargin)
84
+ printMessage(m.explanation)
85
+ }
88
86
89
87
90
- override def summary : String = {
88
+ override def summary ( implicit ctx : Context ) : String = {
91
89
val b = new mutable.ListBuffer [String ]
92
90
if (warningCount > 0 )
93
- b += countString(warningCount, Yellow (" warning" )) + " found"
91
+ b += countString(warningCount, Yellow (" warning" ).show ) + " found"
94
92
if (errorCount > 0 )
95
- b += countString(errorCount, Red (" error" )) + " found"
93
+ b += countString(errorCount, Red (" error" ).show ) + " found"
96
94
for ((settingName, count) <- unreportedWarnings)
97
- b += s " there were $count ${settingName.tail} ${Yellow (" warning(s)" )}; re-run with $settingName for details "
95
+ b += s " there were $count ${settingName.tail} ${Yellow (" warning(s)" ).show }; re-run with $settingName for details "
98
96
b.mkString(" \n " )
99
97
}
100
98
}
0 commit comments