diff options
author | Paul Phillips <paulp@improving.org> | 2011-01-29 19:27:13 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-01-29 19:27:13 +0000 |
commit | f89016a8736f7b09ea1dd74baa6c45bb39e47444 (patch) | |
tree | 332c043a83574c6c2e1e9788439dacadceafb6f9 /src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala | |
parent | 80488e4218a0a72dec3ba727e6de276da87f1398 (diff) | |
download | scala-f89016a8736f7b09ea1dd74baa6c45bb39e47444.tar.gz scala-f89016a8736f7b09ea1dd74baa6c45bb39e47444.tar.bz2 scala-f89016a8736f7b09ea1dd74baa6c45bb39e47444.zip |
Bringing lots more encapsulation to the repl.
interfaces from implementations and isolating jline better so it doesn't
become an accidental dependency or have other unexpected effects. No
review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala index e7ef50ddf7..1a67cc647d 100644 --- a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala +++ b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala @@ -10,38 +10,35 @@ import java.io.IOException import java.nio.channels.ClosedByInterruptException import scala.util.control.Exception._ import InteractiveReader._ +import Properties.isMac /** Reads lines from an input stream */ trait InteractiveReader { val interactive: Boolean - protected def readOneLine(prompt: String): String def history: History def completion: Completion + def init(): Unit def reset(): Unit - def redrawLine(): Unit = () - def currentLine = "" // the current buffer contents, if available - - def readLine(prompt: String): String = { - def handler: Catcher[String] = { - case e: ClosedByInterruptException => sys.error("Reader closed by interrupt.") - // Terminal has to be re-initialized after SIGSTP or up arrow etc. stop working. - case e: IOException if restartSystemCall(e) => reset() ; readLine(prompt) - } - catching(handler) { readOneLine(prompt) } - } + protected def readOneLine(prompt: String): String + def redrawLine(): Unit + def currentLine: String - // hack necessary for OSX jvm suspension because read calls are not restarted after SIGTSTP - private def restartSystemCall(e: Exception): Boolean = - Properties.isMac && (e.getMessage == msgEINTR) + def readLine(prompt: String): String = + // hack necessary for OSX jvm suspension because read calls are not restarted after SIGTSTP + if (isMac) restartSysCalls(readOneLine(prompt), reset()) + else readOneLine(prompt) } object InteractiveReader { val msgEINTR = "Interrupted system call" - def apply(): InteractiveReader = new SimpleReader + def restartSysCalls[R](body: => R, reset: => Unit): R = + try body catch { + case e: IOException if e.getMessage == msgEINTR => reset ; body + } - // @deprecated("Use `apply` instead") def createDefault(intp: IMain): InteractiveReader = apply(intp) - // @deprecated("Use `apply` instead") def createDefault(comp: Completion): InteractiveReader = apply(comp) + def apply(): InteractiveReader = SimpleReader() } + |