From 8a2df2dc7066210d6db00c42bf9312b8c237b0f7 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 10 Apr 2011 02:17:28 +0000 Subject: Made the reading of y/n a little more robust. --- .../scala/tools/nsc/interpreter/ILoop.scala | 22 ++++++++++++++-------- .../tools/nsc/interpreter/InteractiveReader.scala | 7 ++++--- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'src/compiler') 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 -- cgit v1.2.3