blob: 116cc04ce463e3cf91775f95bf159e903c6d6dd4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/* NSC -- new Scala compiler
* Copyright 2005-2008 LAMP/EPFL
* @author Stepan Koltsov
*/
// $Id$
package scala.tools.nsc.interpreter
/** Reads lines from an input stream */
trait InteractiveReader {
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 = System.getProperty("java.vendor", "")
val msgEINTR = "Interrupted system call"
/** Create an interactive reader. Uses <code>JLineReader</code> if the
* library is available, but otherwise uses a
* <code>SimpleReaderi</code>. */
def createDefault(): InteractiveReader =
try {
new JLineReader
} catch {
case e =>
//out.println("jline is not available: " + e) //debug
new SimpleReader()
}
}
|