diff options
3 files changed, 31 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala index d928ec00ae..2c90d87975 100644 --- a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala +++ b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala @@ -8,25 +8,42 @@ package scala.tools.nsc.interpreter /** Reads lines from an input stream */ trait InteractiveReader { - def readLine(prompt: String): String + import InteractiveReader._ + import java.io.IOException + + protected def readOneLine(prompt: String): String val interactive: Boolean + + def readLine(prompt: String): String = + try { + readOneLine(prompt) + } + catch { + case e: IOException if restartSystemCall(e) => readLine(prompt) + case e => throw e + } + + private def restartSystemCall(e: Exception): Boolean = + (vendor startsWith "Apple") && (e.getMessage == msgEINTR) } object InteractiveReader { + // hacks necessary for OSX jvm suspension because read calls are not restarted after SIGTSTP + val vendor = { val v = System.getProperty("java.vendor") ; if (v == null) "" else v } + val msgEINTR = "Interrupted system call" + /** Create an interactive reader. Uses JLine if the * library is available, but otherwise uses a * SimpleReader. */ - def createDefault(): InteractiveReader = { - try { - new JLineReader - } catch { - case e => - //out.println("jline is not available: " + e) //debug - new SimpleReader() - } - } - - + def createDefault(): InteractiveReader = { + try { + new JLineReader + } catch { + case e => + //out.println("jline is not available: " + e) //debug + new SimpleReader() + } + } } diff --git a/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala b/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala index b3647178e3..b0fa3f40db 100644 --- a/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala +++ b/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala @@ -22,7 +22,7 @@ class JLineReader extends InteractiveReader { r.setBellEnabled(false) r } - def readLine(prompt: String) = consoleReader.readLine(prompt) + def readOneLine(prompt: String) = consoleReader.readLine(prompt) val interactive = true } diff --git a/src/compiler/scala/tools/nsc/interpreter/SimpleReader.scala b/src/compiler/scala/tools/nsc/interpreter/SimpleReader.scala index 1961ba761c..4882dfc28b 100644 --- a/src/compiler/scala/tools/nsc/interpreter/SimpleReader.scala +++ b/src/compiler/scala/tools/nsc/interpreter/SimpleReader.scala @@ -16,7 +16,7 @@ class SimpleReader( extends InteractiveReader { def this() = this(Console.in, new PrintWriter(Console.out), true) - def readLine(prompt: String) = { + def readOneLine(prompt: String) = { if (interactive) { out.print(prompt) out.flush() |