diff options
author | Antoine Gourlay <antoine@gourlay.fr> | 2014-07-29 18:12:42 +0200 |
---|---|---|
committer | Antoine Gourlay <antoine@gourlay.fr> | 2014-07-29 20:04:33 +0200 |
commit | ed9dfee181e56bb83afa0598523786bee5572068 (patch) | |
tree | cb11f1943a15412eb294ce0dab01b9d1a4ae4d4d /src | |
parent | 84d4ebc19a1e54dbe446ef35b71efa7ad3890c19 (diff) | |
download | scala-ed9dfee181e56bb83afa0598523786bee5572068.tar.gz scala-ed9dfee181e56bb83afa0598523786bee5572068.tar.bz2 scala-ed9dfee181e56bb83afa0598523786bee5572068.zip |
SI-4563 friendlier behavior for Ctrl+D in the REPL
Closing the REPL with Ctrl+D does not issue a newline, so the user's
prompt displays on the same line as the `scala>` prompt. This is bad.
We now force a newline before closing the interpreter, and display
`:quit` while we're at it so that people know how to exit the REPL
(since `exit` doesn't exist anymore).
The tricky part was to only add a newline when the console is
interrupted, and *not* when it is closed by a command (like `:quit`),
since commands are processed after their text (including newline) has
been sent to the console.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/Properties.scala | 1 | ||||
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/ILoop.scala | 9 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/Properties.scala b/src/compiler/scala/tools/nsc/Properties.scala index ed5fda9c3f..59fefba954 100644 --- a/src/compiler/scala/tools/nsc/Properties.scala +++ b/src/compiler/scala/tools/nsc/Properties.scala @@ -14,6 +14,7 @@ object Properties extends scala.util.PropertiesTrait { // settings based on jar properties def residentPromptString = scalaPropOrElse("resident.prompt", "\nnsc> ") def shellPromptString = scalaPropOrElse("shell.prompt", "\nscala> ") + def shellInterruptedString = scalaPropOrElse("shell.interrupted", ":quit\n") // derived values def isEmacsShell = propOrEmpty("env.emacs") != "" diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala index ce0eadc04f..50c89f7442 100644 --- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala @@ -430,7 +430,14 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) import scala.concurrent.duration._ Await.ready(globalFuture, 60.seconds) - (line ne null) && (command(line) match { + if (line eq null) { + // SI-4563: this means the console was properly interrupted (Ctrl+D usually) + // so we display the output message (which by default ends with + // a newline so as not to break the user's terminal) + if (in.interactive) out.print(Properties.shellInterruptedString) + + false + } else (command(line) match { case Result(false, _) => false case Result(_, Some(line)) => addReplay(line) ; true case _ => true |