summaryrefslogtreecommitdiff
path: root/src/repl/scala/tools/nsc/interpreter
diff options
context:
space:
mode:
Diffstat (limited to 'src/repl/scala/tools/nsc/interpreter')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/Formatting.scala3
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala27
-rw-r--r--src/repl/scala/tools/nsc/interpreter/IMain.scala4
-rw-r--r--src/repl/scala/tools/nsc/interpreter/Pasted.scala8
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ReplProps.scala46
5 files changed, 61 insertions, 27 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/Formatting.scala b/src/repl/scala/tools/nsc/interpreter/Formatting.scala
index 844997429c..4a9548730a 100644
--- a/src/repl/scala/tools/nsc/interpreter/Formatting.scala
+++ b/src/repl/scala/tools/nsc/interpreter/Formatting.scala
@@ -30,3 +30,6 @@ class Formatting(indent: Int) {
}
)
}
+object Formatting {
+ def forPrompt(prompt: String) = new Formatting(prompt.lines.toList.last.length)
+}
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
index e8c6d02d1e..612bdd98c9 100644
--- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
@@ -56,13 +56,9 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
private var globalFuture: Future[Boolean] = _
- /** Print a welcome message */
- def printWelcome() {
- echo(s"""
- |Welcome to Scala $versionString ($javaVmName, Java $javaVersion).
- |Type in expressions to have them evaluated.
- |Type :help for more information.""".trim.stripMargin
- )
+ /** Print a welcome message! */
+ def printWelcome(): Unit = {
+ Option(replProps.welcome) filter (!_.isEmpty) foreach echo
replinfo("[info] started at " + new java.util.Date)
}
@@ -111,10 +107,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
class ILoopInterpreter extends IMain(settings, out) {
- // the expanded prompt but without color escapes and without leading newline, for purposes of indenting
- override lazy val formatting: Formatting = new Formatting(
- (replProps.promptString format Properties.versionNumberString).lines.toList.last.length
- )
override protected def parentClassLoader =
settings.explicitParentLoader.getOrElse( classOf[ILoop].getClassLoader )
}
@@ -679,9 +671,8 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
def verbosity() = {
- val old = intp.printResults
- intp.printResults = !old
- echo("Switched " + (if (old) "off" else "on") + " result printing.")
+ intp.printResults = !intp.printResults
+ replinfo(s"Result printing is ${ if (intp.printResults) "on" else "off" }.")
}
/** Run one command submitted by the user. Two values are returned:
@@ -761,7 +752,8 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
private object paste extends Pasted {
import scala.util.matching.Regex.quote
- val ContinueString = " | "
+ val ContinuePrompt = replProps.continuePrompt
+ val ContinueString = replProps.continueText // " | "
val PromptString = prompt.lines.toList.last
val anyPrompt = s"""\\s*(?:${quote(PromptString.trim)}|${quote(AltPromptString.trim)})\\s*""".r
@@ -805,7 +797,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
echo("You typed two blank lines. Starting a new command.")
None
case IR.Incomplete =>
- in.readLine(paste.ContinueString) match {
+ in.readLine(paste.ContinuePrompt) match {
case null =>
// we know compilation is going to fail since we're at EOF and the
// parser thinks the input is still incomplete, but since this is
@@ -948,8 +940,9 @@ object ILoop {
Console.withOut(ostream) {
val output = new JPrintWriter(new OutputStreamWriter(ostream), true) {
// skip margin prefix for continuation lines, unless preserving session text for test
+ // should test for repl.paste.ContinueString or replProps.continueText.contains(ch)
override def write(str: String) =
- if (!inSession && (str forall (ch => ch.isWhitespace || ch == '|'))) () // repl.paste.ContinueString
+ if (!inSession && (str forall (ch => ch.isWhitespace || ch == '|'))) ()
else super.write(str)
}
val input = new BufferedReader(new StringReader(code.trim + "\n")) {
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala
index 2550a5dc57..841b4abfa5 100644
--- a/src/repl/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala
@@ -113,9 +113,7 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
def this() = this(new Settings())
// the expanded prompt but without color escapes and without leading newline, for purposes of indenting
- lazy val formatting: Formatting = new Formatting(
- (replProps.promptString format Properties.versionNumberString).lines.toList.last.length
- )
+ lazy val formatting = Formatting.forPrompt(replProps.promptText)
lazy val reporter: ReplReporter = new ReplReporter(this)
import formatting.indentCode
diff --git a/src/repl/scala/tools/nsc/interpreter/Pasted.scala b/src/repl/scala/tools/nsc/interpreter/Pasted.scala
index 5f388eb15b..f8d8c2ddb1 100644
--- a/src/repl/scala/tools/nsc/interpreter/Pasted.scala
+++ b/src/repl/scala/tools/nsc/interpreter/Pasted.scala
@@ -21,7 +21,13 @@ abstract class Pasted {
def PromptString: String
def AltPromptString: String = "scala> "
- private val testBoth = PromptString != AltPromptString
+ /* `testBoth` cannot be a val, as `Pasted` is inherited by `object paste` in ILoop,
+ which would cause `val testBoth` to be initialized before `val PromptString` was.
+
+ object paste extends Pasted {
+ val PromptString = prompt.lines.toList.last
+ */
+ private def testBoth = PromptString != AltPromptString
private val spacey = " \t".toSet
def matchesPrompt(line: String) = matchesString(line, PromptString) || testBoth && matchesString(line, AltPromptString)
diff --git a/src/repl/scala/tools/nsc/interpreter/ReplProps.scala b/src/repl/scala/tools/nsc/interpreter/ReplProps.scala
index df65e9974d..588d92f81b 100644
--- a/src/repl/scala/tools/nsc/interpreter/ReplProps.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ReplProps.scala
@@ -6,9 +6,11 @@
package scala.tools.nsc
package interpreter
-import Properties.shellPromptString
+import Properties.{ javaVersion, javaVmName, shellPromptString, shellWelcomeString,
+ versionString, versionNumberString }
import scala.sys._
import Prop._
+import java.util.{ Formattable, FormattableFlags, Formatter }
class ReplProps {
private def bool(name: String) = BooleanProp.keyExists(name)
@@ -22,12 +24,44 @@ class ReplProps {
val trace = bool("scala.repl.trace")
val power = bool("scala.repl.power")
- // Handy system prop for shell prompt, or else pick it up from compiler.properties
- val promptString = Prop[String]("scala.repl.prompt").option getOrElse (if (info) "%nscala %s> " else shellPromptString)
- val prompt = {
+ def enversion(s: String) = {
+ import FormattableFlags._
+ val v = new Formattable {
+ override def formatTo(formatter: Formatter, flags: Int, width: Int, precision: Int) = {
+ val version = if ((flags & ALTERNATE) != 0) versionNumberString else versionString
+ val left = if ((flags & LEFT_JUSTIFY) != 0) "-" else ""
+ val w = if (width >= 0) s"$width" else ""
+ val p = if (precision >= 0) s".$precision" else ""
+ val fmt = s"%${left}${w}${p}s"
+ formatter.format(fmt, version)
+ }
+ }
+ s.format(v, javaVersion, javaVmName)
+ }
+ def encolor(s: String) = {
import scala.io.AnsiColor.{ MAGENTA, RESET }
- val p = promptString format Properties.versionNumberString
- if (colorOk) s"$MAGENTA$p$RESET" else p
+ if (colorOk) s"$MAGENTA$s$RESET" else s
+ }
+
+ // Handy system prop for shell prompt, or else pick it up from compiler.properties
+ val promptString = Prop[String]("scala.repl.prompt").option getOrElse (if (info) "%nscala %#s> " else shellPromptString)
+ val promptText = enversion(promptString)
+ val prompt = encolor(promptText)
+
+ // Prompt for continued input, will be right-adjusted to width of the primary prompt
+ val continueString = Prop[String]("scala.repl.continue").option getOrElse "| "
+ val continueText = {
+ val text = enversion(continueString)
+ val margin = promptText.lines.toList.last.length - text.length
+ if (margin > 0) " " * margin + text else text
+ }
+ val continuePrompt = encolor(continueText)
+
+ // Next time.
+ //def welcome = enversion(Prop[String]("scala.repl.welcome") or shellWelcomeString)
+ def welcome = enversion {
+ val p = Prop[String]("scala.repl.welcome")
+ if (p.isSet) p.get else shellWelcomeString
}
/** CSV of paged,across to enable pagination or `-x` style