aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-05-20 10:47:53 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-05-20 10:47:53 +0200
commita5db35def41d10e4e84dc294e55fbfd79ebc8cab (patch)
tree5c04f10bb376b4076bb769d923e0844408b36d91 /src/dotty/tools/dotc
parent799007fcf66b5d4299f31533d57a8eee1a345c22 (diff)
downloaddotty-a5db35def41d10e4e84dc294e55fbfd79ebc8cab.tar.gz
dotty-a5db35def41d10e4e84dc294e55fbfd79ebc8cab.tar.bz2
dotty-a5db35def41d10e4e84dc294e55fbfd79ebc8cab.zip
Factor out coloring check to new method `Context#useColors`
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala4
-rw-r--r--src/dotty/tools/dotc/repl/AmmoniteReader.scala3
-rw-r--r--src/dotty/tools/dotc/repl/CompilingInterpreter.scala11
3 files changed, 10 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index bbe8e920c..68ae0e752 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -370,6 +370,10 @@ object Contexts {
/** Is the verbose option set? */
def verbose: Boolean = base.settings.verbose.value
+ /** Should use colors when printing? */
+ def useColors: Boolean =
+ List("auto", "always") contains base.settings.color.value
+
/** A condensed context containing essential information of this but
* no outer contexts except the initial context.
private var _condensed: CondensedContext = null
diff --git a/src/dotty/tools/dotc/repl/AmmoniteReader.scala b/src/dotty/tools/dotc/repl/AmmoniteReader.scala
index c02a14451..614654a28 100644
--- a/src/dotty/tools/dotc/repl/AmmoniteReader.scala
+++ b/src/dotty/tools/dotc/repl/AmmoniteReader.scala
@@ -58,8 +58,7 @@ class AmmoniteReader(val interpreter: Interpreter)(implicit ctx: Context) extend
allFilters,
displayTransform = (buffer, cursor) => {
val coloredBuffer =
- if (List("auto", "always").contains(ctx.settings.color.value))
- SyntaxHighlighting(buffer)
+ if (ctx.useColors) SyntaxHighlighting(buffer)
else buffer
val ansiBuffer = Ansi.Str.parse(coloredBuffer)
diff --git a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
index 700909fd0..7b8ba698a 100644
--- a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
+++ b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
@@ -406,7 +406,7 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
}
/** load and run the code using reflection.
- * @return A pair consisting of the run's result as a string, and
+ * @return A pair consisting of the run's result as a `List[String]`, and
* a boolean indicating whether the run succeeded without throwing
* an exception.
*/
@@ -417,12 +417,11 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
interpreterResultObject.getMethod("result")
try {
withOutput(new ByteOutputStream) { ps =>
- val rawRes = valMethodRes.invoke(interpreterResultObject).toString
- val res =
- if (List("auto", "always").contains(ictx.settings.color.value))
- new String(SyntaxHighlighting(rawRes).toArray)
+ val rawRes = valMethodRes.invoke(interpreterResultObject).toString
+ val res =
+ if (ictx.useColors) new String(SyntaxHighlighting(rawRes).toArray)
else rawRes
- val prints = ps.toString("utf-8")
+ val prints = ps.toString("utf-8")
val printList = if (prints != "") prints :: Nil else Nil
if (!delayOutput) out.print(prints)