aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-05-12 14:26:16 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-05-12 14:26:16 +0200
commitdc36755731c92771647531427e390076e558567d (patch)
tree03e7cea4c0bf8a1487a8b03ccd0f98bb06254376
parentfdf24243ffa07bdcef94032234d36170363bd8bb (diff)
downloaddotty-dc36755731c92771647531427e390076e558567d.tar.gz
dotty-dc36755731c92771647531427e390076e558567d.tar.bz2
dotty-dc36755731c92771647531427e390076e558567d.zip
Add CLI option to disable REPL syntax highlighting
-rw-r--r--src/dotty/tools/dotc/config/ScalaSettings.scala1
-rw-r--r--src/dotty/tools/dotc/repl/AmmoniteReader.scala5
-rw-r--r--src/dotty/tools/dotc/repl/CompilingInterpreter.scala9
-rw-r--r--src/dotty/tools/dotc/repl/REPL.scala7
-rw-r--r--test/test/TestREPL.scala6
5 files changed, 21 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala
index f9c10442a..09234fb3c 100644
--- a/src/dotty/tools/dotc/config/ScalaSettings.scala
+++ b/src/dotty/tools/dotc/config/ScalaSettings.scala
@@ -94,6 +94,7 @@ class ScalaSettings extends Settings.SettingGroup {
val sourceReader = StringSetting("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "")
val XnoValueClasses = BooleanSetting("-Xno-value-classes", "Do not use value classes. Helps debugging.")
val XreplLineWidth = IntSetting("-Xrepl-line-width", "Maximial number of columns per line for REPL output", 390)
+ val XreplNoColor = BooleanSetting("-Xrepl-no-color", "Removes syntax highlighting in REPL")
val XoldPatmat = BooleanSetting("-Xoldpatmat", "Use the pre-2.10 pattern matcher. Otherwise, the 'virtualizing' pattern matcher is used in 2.10.")
val XnoPatmatAnalysis = BooleanSetting("-Xno-patmat-analysis", "Don't perform exhaustivity/unreachability analysis. Also, ignore @switch annotation.")
val XfullLubs = BooleanSetting("-Xfull-lubs", "Retains pre 2.10 behavior of less aggressive truncation of least upper bounds.")
diff --git a/src/dotty/tools/dotc/repl/AmmoniteReader.scala b/src/dotty/tools/dotc/repl/AmmoniteReader.scala
index e399105b3..508257e44 100644
--- a/src/dotty/tools/dotc/repl/AmmoniteReader.scala
+++ b/src/dotty/tools/dotc/repl/AmmoniteReader.scala
@@ -57,7 +57,10 @@ class AmmoniteReader(val interpreter: Interpreter)(implicit ctx: Context) extend
writer,
allFilters,
displayTransform = (buffer, cursor) => {
- val ansiBuffer = Ansi.Str.parse(SyntaxHighlighting(buffer))
+ val coloredBuffer =
+ if (!ctx.settings.XreplNoColor.value) SyntaxHighlighting(buffer)
+ else buffer
+ val ansiBuffer = Ansi.Str.parse(coloredBuffer)
val (newBuffer, cursorOffset) = SelectionFilter.mangleBuffer(
selectionFilter, ansiBuffer, cursor, Ansi.Reversed.On
)
diff --git a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
index fd16bc481..7de7a4bd6 100644
--- a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
+++ b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
@@ -418,11 +418,12 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
try {
withOutput(new ByteOutputStream) { ps =>
val rawRes = valMethodRes.invoke(interpreterResultObject).toString
- val res = new String(SyntaxHighlighting(rawRes).toArray)
+ val res =
+ if (!ictx.settings.XreplNoColor.value)
+ new String(SyntaxHighlighting(rawRes).toArray)
+ else rawRes
val prints = ps.toString("utf-8")
- val printList =
- if (prints == "") Nil
- else prints :: Nil
+ val printList = if (prints != "") prints :: Nil else Nil
if (!delayOutput) out.print(prints)
diff --git a/src/dotty/tools/dotc/repl/REPL.scala b/src/dotty/tools/dotc/repl/REPL.scala
index 1f5e3347b..977f67719 100644
--- a/src/dotty/tools/dotc/repl/REPL.scala
+++ b/src/dotty/tools/dotc/repl/REPL.scala
@@ -25,6 +25,11 @@ class REPL extends Driver {
lazy val config = new REPL.Config
+ override def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
+ val (strs, ctx) = super.setup(args, rootCtx)
+ (strs, config.context(ctx))
+ }
+
override def newCompiler(implicit ctx: Context): Compiler =
new repl.CompilingInterpreter(config.output, ctx)
@@ -45,6 +50,8 @@ object REPL {
val continuationPrompt = " | "
val version = ".next (pre-alpha)"
+ def context(ctx: Context): Context = ctx
+
/** The default input reader */
def input(in: Interpreter)(implicit ctx: Context): InteractiveReader = {
val emacsShell = System.getProperty("env.emacs", "") != ""
diff --git a/test/test/TestREPL.scala b/test/test/TestREPL.scala
index ab31af636..2beb9e40b 100644
--- a/test/test/TestREPL.scala
+++ b/test/test/TestREPL.scala
@@ -20,6 +20,9 @@ class TestREPL(script: String) extends REPL {
override lazy val config = new REPL.Config {
override val output = new NewLinePrintWriter(out)
+ override def context(ctx: Context) =
+ ctx.fresh.setSetting(ctx.settings.XreplNoColor, true)
+
override def input(in: Interpreter)(implicit ctx: Context) = new InteractiveReader {
val lines = script.lines
def readLine(prompt: String): String = {
@@ -38,8 +41,7 @@ class TestREPL(script: String) extends REPL {
out.close()
val printed = out.toString
val transcript = printed.drop(printed.indexOf(config.prompt))
- val transcriptNoColors = transcript.toString.replaceAll("\u001B\\[[;\\d]*m", "")
- if (transcriptNoColors != script) {
+ if (transcript.toString != script) {
println("input differs from transcript:")
println(transcript)
assert(false)