66package scala .tools .nsc
77package interpreter
88
9- import Properties .shellPromptString
9+ import Properties .{ javaVersion , javaVmName , shellPromptString , shellWelcomeString ,
10+ versionString , versionNumberString }
1011import scala .sys ._
1112import Prop ._
13+ import java .util .{ Formattable , FormattableFlags , Formatter }
1214
1315class ReplProps {
1416 private def bool (name : String ) = BooleanProp .keyExists(name)
@@ -22,12 +24,37 @@ class ReplProps {
2224 val trace = bool(" scala.repl.trace" )
2325 val power = bool(" scala.repl.power" )
2426
27+ def enversion (s : String ) = {
28+ import FormattableFlags ._
29+ val v = new Formattable {
30+ override def formatTo (formatter : Formatter , flags : Int , width : Int , precision : Int ) = {
31+ val version = if ((flags & ALTERNATE ) != 0 ) versionNumberString else versionString
32+ val left = if ((flags & LEFT_JUSTIFY ) != 0 ) " -" else " "
33+ val w = if (width >= 0 ) s " $width" else " "
34+ val p = if (precision >= 0 ) s " . $precision" else " "
35+ val fmt = s " % ${left}${w}${p}s "
36+ formatter.format(fmt, version)
37+ }
38+ }
39+ s.format(v, javaVersion, javaVmName)
40+ }
41+ def encolor (s : String ) = {
42+ import scala .io .AnsiColor .{ MAGENTA , RESET }
43+ if (colorOk) s " $MAGENTA$s$RESET" else s
44+ }
45+
2546 // Handy system prop for shell prompt, or else pick it up from compiler.properties
2647 val promptString = Prop [String ](" scala.repl.prompt" ).option getOrElse (if (info) " %nscala %s> " else shellPromptString)
48+ def promptText = enversion(promptString)
2749 val prompt = {
2850 import scala .io .AnsiColor .{ MAGENTA , RESET }
29- val p = promptString format Properties .versionNumberString
30- if (colorOk) s " $MAGENTA$p$RESET" else p
51+ if (colorOk) s " $MAGENTA$promptText$RESET" else promptText
52+ }
53+
54+ // def welcome = enversion(Prop[String]("scala.repl.welcome") or shellWelcomeString)
55+ def welcome = enversion {
56+ val p = Prop [String ](" scala.repl.welcome" )
57+ if (p.isSet) p.value else shellWelcomeString
3158 }
3259
3360 /** CSV of paged,across to enable pagination or `-x` style
0 commit comments