diff options
author | Geoffrey Washburn <geoffrey.washburn@epfl.ch> | 2008-10-18 15:51:30 +0000 |
---|---|---|
committer | Geoffrey Washburn <geoffrey.washburn@epfl.ch> | 2008-10-18 15:51:30 +0000 |
commit | b2e8634221054e1f0bc989c8c165aafa30e0528b (patch) | |
tree | 0f41f799b72077f5446d71f58c1d32e90b757424 | |
parent | 973ac733622eb9409c8c5ffcf05ba14775e07b18 (diff) | |
download | scala-b2e8634221054e1f0bc989c8c165aafa30e0528b.tar.gz scala-b2e8634221054e1f0bc989c8c165aafa30e0528b.tar.bz2 scala-b2e8634221054e1f0bc989c8c165aafa30e0528b.zip |
Contributed fix for #1416
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() |