diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-05-12 14:26:16 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-05-12 14:26:16 +0200 |
commit | dc36755731c92771647531427e390076e558567d (patch) | |
tree | 03e7cea4c0bf8a1487a8b03ccd0f98bb06254376 /src | |
parent | fdf24243ffa07bdcef94032234d36170363bd8bb (diff) | |
download | dotty-dc36755731c92771647531427e390076e558567d.tar.gz dotty-dc36755731c92771647531427e390076e558567d.tar.bz2 dotty-dc36755731c92771647531427e390076e558567d.zip |
Add CLI option to disable REPL syntax highlighting
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/config/ScalaSettings.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/repl/AmmoniteReader.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/repl/CompilingInterpreter.scala | 9 | ||||
-rw-r--r-- | src/dotty/tools/dotc/repl/REPL.scala | 7 |
4 files changed, 17 insertions, 5 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", "") != "" |