forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsoleReporter.scala
38 lines (31 loc) · 1.12 KB
/
ConsoleReporter.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package dotty.tools
package dotc
package reporting
import core.Contexts._
import java.io.{ BufferedReader, PrintWriter }
import Diagnostic.{ Error, ConditionalWarning }
/**
* This class implements a Reporter that displays messages on a text console
*/
class ConsoleReporter(
reader: BufferedReader = Console.in,
writer: PrintWriter = new PrintWriter(Console.err, true)
) extends AbstractReporter {
import Diagnostic._
/** Prints the message. */
def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }
/** Prints the message with the given position indication. */
def doReport(dia: Diagnostic)(using Context): Unit = {
dia match
case dia: Error =>
printMessage(messageAndPos(dia))
if (ctx.settings.Xprompt.value) Reporter.displayPrompt(reader, writer)
case dia =>
printMessage(messageAndPos(dia))
if shouldExplain(dia) then
printMessage(explanation(dia.msg))
else if dia.msg.canExplain then
printMessage("\nlonger explanation available when compiling with `-explain`")
}
override def flush()(using Context): Unit = { writer.flush() }
}