Skip to content

Commit 799007f

Browse files
committed
Use ChoiceSetting for coloring
1 parent dc36755 commit 799007f

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ScalaSettings extends Settings.SettingGroup {
2828
val help = BooleanSetting("-help", "Print a synopsis of standard options")
2929
val nowarn = BooleanSetting("-nowarn", "Generate no warnings.")
3030
val print = BooleanSetting("-print", "Print program with Scala-specific features removed.")
31+
val color = ChoiceSetting("-color", "mode", "Colored output", List("always", "never", "auto"), "auto")
3132
val target = ChoiceSetting("-target", "target", "Target platform for object files. All JVM 1.5 targets are deprecated.",
3233
List("jvm-1.5", "jvm-1.5-fjbg", "jvm-1.5-asm", "jvm-1.6", "jvm-1.7", "jvm-1.8", "msil"),
3334
"jvm-1.8")
@@ -94,7 +95,6 @@ class ScalaSettings extends Settings.SettingGroup {
9495
val sourceReader = StringSetting("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "")
9596
val XnoValueClasses = BooleanSetting("-Xno-value-classes", "Do not use value classes. Helps debugging.")
9697
val XreplLineWidth = IntSetting("-Xrepl-line-width", "Maximial number of columns per line for REPL output", 390)
97-
val XreplNoColor = BooleanSetting("-Xrepl-no-color", "Removes syntax highlighting in REPL")
9898
val XoldPatmat = BooleanSetting("-Xoldpatmat", "Use the pre-2.10 pattern matcher. Otherwise, the 'virtualizing' pattern matcher is used in 2.10.")
9999
val XnoPatmatAnalysis = BooleanSetting("-Xno-patmat-analysis", "Don't perform exhaustivity/unreachability analysis. Also, ignore @switch annotation.")
100100
val XfullLubs = BooleanSetting("-Xfull-lubs", "Retains pre 2.10 behavior of less aggressive truncation of least upper bounds.")

src/dotty/tools/dotc/repl/AmmoniteReader.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ class AmmoniteReader(val interpreter: Interpreter)(implicit ctx: Context) extend
5858
allFilters,
5959
displayTransform = (buffer, cursor) => {
6060
val coloredBuffer =
61-
if (!ctx.settings.XreplNoColor.value) SyntaxHighlighting(buffer)
61+
if (List("auto", "always").contains(ctx.settings.color.value))
62+
SyntaxHighlighting(buffer)
6263
else buffer
64+
6365
val ansiBuffer = Ansi.Str.parse(coloredBuffer)
6466
val (newBuffer, cursorOffset) = SelectionFilter.mangleBuffer(
6567
selectionFilter, ansiBuffer, cursor, Ansi.Reversed.On

src/dotty/tools/dotc/repl/CompilingInterpreter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
419419
withOutput(new ByteOutputStream) { ps =>
420420
val rawRes = valMethodRes.invoke(interpreterResultObject).toString
421421
val res =
422-
if (!ictx.settings.XreplNoColor.value)
422+
if (List("auto", "always").contains(ictx.settings.color.value))
423423
new String(SyntaxHighlighting(rawRes).toArray)
424424
else rawRes
425425
val prints = ps.toString("utf-8")

test/test/TestREPL.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TestREPL(script: String) extends REPL {
2121
override val output = new NewLinePrintWriter(out)
2222

2323
override def context(ctx: Context) =
24-
ctx.fresh.setSetting(ctx.settings.XreplNoColor, true)
24+
ctx.fresh.setSetting(ctx.settings.color, "never")
2525

2626
override def input(in: Interpreter)(implicit ctx: Context) = new InteractiveReader {
2727
val lines = script.lines

0 commit comments

Comments
 (0)