diff options
author | Som Snytt <som.snytt@gmail.com> | 2014-10-16 11:15:16 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2014-11-04 09:12:27 -0800 |
commit | 126effe46005673ca826045e9cb037096d68af90 (patch) | |
tree | 1c6768a7d8d7a1e55a358aabd5ea68e61656874b /src/repl/scala/tools/nsc/interpreter/SimpleReader.scala | |
parent | 2b5df373638d08204b71258928289f6b39e25d5f (diff) | |
download | scala-126effe46005673ca826045e9cb037096d68af90.tar.gz scala-126effe46005673ca826045e9cb037096d68af90.tar.bz2 scala-126effe46005673ca826045e9cb037096d68af90.zip |
SI-8922 REPL load -v
Verbose mode causes the familiar prompt and
line echo so you can see what you just loaded.
The quit message is pushed up a level in the
process loop.
This has the huge payoff that if you start the
repl and immediately hit ctl-D, you don't have to
wait for the compiler to init (yawn) before you
get a shell prompt back.
Diffstat (limited to 'src/repl/scala/tools/nsc/interpreter/SimpleReader.scala')
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/SimpleReader.scala | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/SimpleReader.scala b/src/repl/scala/tools/nsc/interpreter/SimpleReader.scala index 6634dc6944..49b8433a8c 100644 --- a/src/repl/scala/tools/nsc/interpreter/SimpleReader.scala +++ b/src/repl/scala/tools/nsc/interpreter/SimpleReader.scala @@ -22,14 +22,19 @@ extends InteractiveReader def reset() = () def redrawLine() = () - def readOneLine(prompt: String): String = { - if (interactive) { - out.print(prompt) - out.flush() - } - in.readLine() + + // InteractiveReader internals + protected def readOneLine(prompt: String): String = { + echo(prompt) + readOneLine() + } + protected def readOneKey(prompt: String) = sys.error("No char-based input in SimpleReader") + + protected def readOneLine(): String = in.readLine() + protected def echo(s: String): Unit = if (interactive) { + out.print(s) + out.flush() } - def readOneKey(prompt: String) = sys.error("No char-based input in SimpleReader") } object SimpleReader { @@ -39,3 +44,13 @@ object SimpleReader { def apply(in: BufferedReader = defaultIn, out: JPrintWriter = defaultOut, interactive: Boolean = true): SimpleReader = new SimpleReader(in, out, interactive) } + +// pretend we are a console for verbose purposes +trait EchoReader extends SimpleReader { + // if there is more input, then maybe echo the prompt and the input + override def readOneLine(prompt: String) = { + val input = readOneLine() + if (input != null) echo(f"$prompt$input%n") + input + } +} |