summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-04-10 02:17:28 +0000
committerPaul Phillips <paulp@improving.org>2011-04-10 02:17:28 +0000
commit8a2df2dc7066210d6db00c42bf9312b8c237b0f7 (patch)
tree7e5243be3b72fdaccf97dc4c6d96401f431fdbb5 /src
parent8e093b517f2c987cb5b4efe8dfb6736d54708e35 (diff)
downloadscala-8a2df2dc7066210d6db00c42bf9312b8c237b0f7.tar.gz
scala-8a2df2dc7066210d6db00c42bf9312b8c237b0f7.tar.bz2
scala-8a2df2dc7066210d6db00c42bf9312b8c237b0f7.zip
Made the reading of y/n a little more robust.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ILoop.scala22
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala7
2 files changed, 18 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
index d1a23f3bc5..b6a6da369f 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
@@ -198,6 +198,15 @@ class ILoop(in0: Option[BufferedReader], protected val out: PrintWriter)
def plush(x: Any) = { out print x ; out.flush() }
def plushln(x: Any) = { out println x ; out.flush() }
+ private def echo(msg: String) = {
+ out println msg
+ out.flush()
+ }
+ private def echoNoNL(msg: String) = {
+ out print msg
+ out.flush()
+ }
+
/** Search the history */
def searchHistory(_cmdline: String) {
val cmdline = _cmdline.toLowerCase
@@ -454,16 +463,13 @@ class ILoop(in0: Option[BufferedReader], protected val out: PrintWriter)
}
ex match {
case _: NoSuchMethodError | _: NoClassDefFoundError =>
- out.println("Unrecoverable error.")
+ echo("Unrecoverable error.")
throw ex
case _ =>
- out.print(replayQuestionMessage)
- out.flush()
- if (in.readAssumingNo("")) {
- out.println("\nAttempting session recovery with replay.")
- replay()
- }
- else out.println("\nAbandoning crashed session.")
+ def fn(): Boolean = in.readYesOrNo(replayQuestionMessage, { echo("\nYou must enter y or n.") ; fn() })
+
+ if (fn()) replay()
+ else echo("\nAbandoning crashed session.")
}
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
index 1430cbe55c..edade4da1b 100644
--- a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
@@ -27,12 +27,13 @@ trait InteractiveReader {
def redrawLine(): Unit
def currentLine: String
- def readYesOrNo(prompt: String) = readOneKey(prompt) match {
+ def readYesOrNo(prompt: String, alt: => Boolean): Boolean = readOneKey(prompt) match {
case 'y' => true
case 'n' => false
+ case _ => alt
}
- def readAssumingNo(prompt: String) = try readYesOrNo(prompt) catch { case _: MatchError => false }
- def readAssumingYes(prompt: String) = try readYesOrNo(prompt) catch { case _: MatchError => true }
+ def readAssumingNo(prompt: String) = readYesOrNo(prompt, false)
+ def readAssumingYes(prompt: String) = readYesOrNo(prompt, true)
protected def readOneLine(prompt: String): String
protected def readOneKey(prompt: String): Int