Skip to content

Commit cad0686

Browse files
committed
Respect -color:never in REPL output
The (successful) result of the REPL was highlighted regardless of the value of `-color`. This commit fixes this, so that the output of the REPL is highlighted only if `-color` is not set to `never`. The prompt and the code as being entered are still highlighted.
1 parent 0c88214 commit cad0686

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class ReplDriver(settings: Array[String],
269269
typeAliases.map("// defined alias " + _.symbol.showUser) ++
270270
defs.map(rendering.renderMethod) ++
271271
vals.map(rendering.renderVal).flatten
272-
).foreach(str => out.println(SyntaxHighlighting(str)))
272+
).foreach(str => out.println(highlight(str)))
273273

274274
state.copy(valIndex = state.valIndex - vals.count(resAndUnit))
275275
}
@@ -284,7 +284,7 @@ class ReplDriver(settings: Array[String],
284284
x.symbol
285285
}
286286
.foreach { sym =>
287-
out.println(SyntaxHighlighting("// defined " + sym.showUser))
287+
out.println(highlight("// defined " + sym.showUser))
288288
}
289289

290290

@@ -339,14 +339,14 @@ class ReplDriver(settings: Array[String],
339339
case TypeOf(expr) =>
340340
compiler.typeOf(expr)(newRun(state)).fold(
341341
displayErrors,
342-
res => out.println(SyntaxHighlighting(res))
342+
res => out.println(highlight(res)(state.context))
343343
)
344344
state
345345

346346
case DocOf(expr) =>
347347
compiler.docOf(expr)(newRun(state)).fold(
348348
displayErrors,
349-
res => out.println(SyntaxHighlighting(res))
349+
res => out.println(highlight(res)(state.context))
350350
)
351351
state
352352

@@ -369,4 +369,11 @@ class ReplDriver(settings: Array[String],
369369
errs.map(renderMessage(_)(state.context)).foreach(out.println)
370370
state
371371
}
372+
373+
/** Add syntax highlighting to `msg` if `color` is not set to `never`. */
374+
private def highlight(msg: Iterable[Char])(implicit ctx: Context): Iterable[Char] = {
375+
if (ctx.settings.color.value != "never") SyntaxHighlighting(msg)
376+
else msg
377+
}
378+
372379
}

0 commit comments

Comments
 (0)