diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-07-13 08:42:11 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-07-13 11:45:02 +1000 |
commit | 18e3e61778918e4e802b8fb75789635409523372 (patch) | |
tree | 18d67da301f0b63667e9393d3e336b1fcb5e1875 /src/repl/scala/tools/nsc/interpreter/ReplProps.scala | |
parent | b92c3aff1ab8c76c4816bd7b1a82a0f87d787837 (diff) | |
parent | 52fde52920d93325310e5544991feeea03e5c763 (diff) | |
download | scala-18e3e61778918e4e802b8fb75789635409523372.tar.gz scala-18e3e61778918e4e802b8fb75789635409523372.tar.bz2 scala-18e3e61778918e4e802b8fb75789635409523372.zip |
Merge remote-tracking branch 'origin/2.11.x' into merge/2.11.x-to-2.12.x-20150713
Conflicts:
src/eclipse/partest/.classpath
src/eclipse/repl/.classpath
test/files/run/nothingTypeNoFramesNoDce.scala
test/files/run/repl-javap-app.check
Also fixup two .classpath files with updated partest, xml and
parser combinators JARs.
Diffstat (limited to 'src/repl/scala/tools/nsc/interpreter/ReplProps.scala')
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/ReplProps.scala | 46 |
1 files changed, 40 insertions, 6 deletions
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 |