Skip to content

Commit

Permalink
Merge pull request scala#3902 from gourlaysama/wip/t4563
Browse files Browse the repository at this point in the history
SI-4563 friendlier behavior for Ctrl+D in the REPL
  • Loading branch information
lrytz committed Aug 12, 2014
2 parents bc0fc0f + ed9dfee commit ed9cca8
Show file tree
Hide file tree
Showing 80 changed files with 89 additions and 81 deletions.
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object Properties extends scala.util.PropertiesTrait {
// settings based on jar properties
def residentPromptString = scalaPropOrElse("resident.prompt", "\nnsc> ")
def shellPromptString = scalaPropOrElse("shell.prompt", "\nscala> ")
def shellInterruptedString = scalaPropOrElse("shell.interrupted", ":quit\n")

// derived values
def isEmacsShell = propOrEmpty("env.emacs") != ""
Expand Down
9 changes: 8 additions & 1 deletion src/repl/scala/tools/nsc/interpreter/ILoop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,14 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
import scala.concurrent.duration._
Await.ready(globalFuture, 60.seconds)

(line ne null) && (command(line) match {
if (line eq null) {
// SI-4563: this means the console was properly interrupted (Ctrl+D usually)
// so we display the output message (which by default ends with
// a newline so as not to break the user's terminal)
if (in.interactive) out.print(Properties.shellInterruptedString)

false
} else (command(line) match {
case Result(false, _) => false
case Result(_, Some(line)) => addReplay(line) ; true
case _ => true
Expand Down
2 changes: 1 addition & 1 deletion test/files/jvm/interpreter.check
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ It would fail on the following inputs: Exp(), Term()
^
f: (e: Exp)Int

scala>
scala> :quit
plusOne: (x: Int)Int
res0: Int = 6
res0: String = after reset
Expand Down
2 changes: 1 addition & 1 deletion test/files/jvm/throws-annot-from-java.check
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ bar
tp.typeParams.isEmpty: true
throws[test.PolymorphicException[_]](classOf[test.PolymorphicException])

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/jvm/xml05.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Type :help for more information.
scala> <city name="San Jos&eacute;"/>
res0: scala.xml.Elem = <city name="San Jos&eacute;"/>

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/class-symbol-contravariant.check
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ res2: Boolean = true
scala> sym.isContravariant // was true
res3: Boolean = false

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/constant-type.check
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Class[String](classOf[java.lang.String])
scala> { ConstantType(Constant(s)); exitingPhase(currentRun.erasurePhase)(println(ConstantType(Constant(s)))); }
Class(classOf[java.lang.String])

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/constrained-types.check
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@ scala> val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message
val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message
^

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/kind-repl-command.check
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ scala> :k Nonexisting
Nonexisting
^

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/lub-visibility.check
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ scala> // but reverted that for SI-5534.
scala> val x = List(List(), Vector())
x: List[scala.collection.immutable.Seq[Nothing] with scala.collection.AbstractSeq[Nothing] with java.io.Serializable] = List(List(), Vector())

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/macro-bundle-repl.check
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ defined term macro foo: Unit

scala> foo

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/macro-repl-basic.check
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ import Macros.Shmacros._
scala> println(foo(2) + Macros.bar(2) * new Macros().quux(4))
31

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/macro-repl-dontexpand.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ bar2: (c: scala.reflect.macros.whitebox.Context)Nothing
scala> def foo2 = macro bar2
defined term macro foo2: Nothing

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/macro-system-properties.check
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ defined object Test
scala> object Test { class C(implicit a: Any) { GrabContext.grab } }
defined object Test

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reflection-equality.check
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ res2: Boolean = true
scala> t2 <:< t1
res3: Boolean = true

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reflection-magicsymbols-repl.check
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ scala.Null
scala.Nothing
scala.Singleton

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reflection-repl-classes.check
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ scala>
scala> mm(new A)
res0: Any = 1

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reflection-repl-elementary.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Type :help for more information.
scala> scala.reflect.runtime.universe.typeOf[List[Nothing]]
res0: reflect.runtime.universe.Type = scala.List[Nothing]

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reify-repl-fail-gracefully.check
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ scala> reify
reify
^

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reify_newimpl_22.check
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ scala> {
^
2

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reify_newimpl_23.check
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ scala> def foo[T]{
^
foo: [T]=> Unit

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reify_newimpl_25.check
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ scala> {
^
TypeTag[x.type]

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reify_newimpl_26.check
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ foo: [T]=> Unit
scala> foo[Int]
WeakTypeTag[scala.List[T]]

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/reify_newimpl_35.check
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ foo: [T](implicit evidence$1: reflect.runtime.universe.TypeTag[T])reflect.runtim
scala> println(foo)
Expr[List[Nothing]](Nil)

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-assign.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ x: Int = 12
scala> y = 13
y: Int = 13

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-bare-expr.check
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ Bovine.x: List[Any] = List(Ruminant(5), Cow, Moooooo)
scala> Bovine.x
res4: List[Any] = List(Ruminant(5), Cow, Moooooo)

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-colon-type.check
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,4 @@ Unit
scala> :type println("side effect!")
Unit

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-empty-package.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Type :help for more information.
scala> println(Bippy.bippy)
bippy!

scala>
scala> :quit
6 changes: 3 additions & 3 deletions test/files/run/repl-javap-app.check
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final void delayedEndpoint$MyApp$1();
Start Length Slot Name Signature
0 9 0 this LMyApp$;

scala>
scala> :quit
#partest java7
Welcome to Scala
Type in expressions to have them evaluated.
Expand All @@ -37,7 +37,7 @@ scala> :javap -app MyApp$
line 5: 0
}

scala>
scala> :quit
#partest java8
Welcome to Scala
Type in expressions to have them evaluated.
Expand All @@ -60,4 +60,4 @@ scala> :javap -app MyApp$
line 5: 0
}

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-out-dir.check
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ repl-out-dir-run.obj
Test$.class
Test.class

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-parens.check
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ scala>
scala> List(1) ++ List('a')
res16: List[AnyVal] = List(1, a)

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-paste-2.check
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ scala> x.length + res5
res3: Int = 129


scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-paste-3.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ scala> println(3)
scala> List(1,2)
res1: List[Int] = List(1, 2)

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-paste-4.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ s"""|Type in expressions to have them evaluated.
|scala> Foo(new Foo)
|res0: Int = 7
|
|scala> """
|scala> :quit"""
def pastie = testPath changeExtension "pastie"
}

2 changes: 1 addition & 1 deletion test/files/run/repl-paste-raw.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ s"""|Type in expressions to have them evaluated.
|scala> favoriteThing.hasString
|res0: Boolean = true
|
|scala> """
|scala> :quit"""
def pastie = testPath changeExtension "pastie"
}
2 changes: 1 addition & 1 deletion test/files/run/repl-paste.check
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ defined class Dingus
defined object Dingus
x: Int = 110

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-power.check
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ m: $r.treedsl.global.Literal = 10
scala> typed(m).tpe // typed is in scope
res2: $r.treedsl.global.Type = Int(10)

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-reset.check
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ defined class BippyBungus
scala> { new BippyBungus ; x1 }
res2: Int = 4

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-save.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ s"""|Type in expressions to have them evaluated.
|
|scala> :save $saveto
|
|scala> """
|scala> :quit"""
def saveto = testOutput / "session.repl"
override def show() = {
super.show()
Expand Down
2 changes: 1 addition & 1 deletion test/files/run/repl-term-macros.check
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ defined term macro foo3: (x: Int)(y: Int)Unit

scala> foo3(2)(3)

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-transcript.check
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ scala> res6.sum + res5
res0: Int = 5273


scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/repl-trim-stack-trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ java.lang.Exception
at .f(<console>:7)
... 69 elided
scala> """
scala> :quit"""

// normalize the "elided" lines because the frame count depends on test context
lazy val elided = """(\s+\.{3} )\d+( elided)""".r
Expand Down
2 changes: 1 addition & 1 deletion test/files/run/repl-type-verbose.check
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ PolyType(
)
)

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t3376.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ m2: M[Float] = mmm
scala> val m3 = new M[String]()
m3: M[String] = mmm

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t4025.check
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ scala>
scala> def f(c: Any) = c match { case Red(_) => () }
f: (c: Any)Unit

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t4172.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ scala> val c = { class C { override def toString = "C" }; ((new C, new C { def f
warning: there was one feature warning; re-run with -feature for details
c: (C, C{def f: Int}) forSome { type C <: AnyRef } = (C,C)

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t4216.check
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ res4: java.util.List[V] = [V@0]
scala> o(new V(0))
res5: java.util.List[Any] = [V@0]

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t4285.check
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ y: scala.collection.mutable.WrappedArray[Int] = WrappedArray(2, 4, 6, 8, 10, 12,
scala> println(y.sum)
56

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t4542.check
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ scala> val f = new Foo
^
f: Foo = Bippy

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t4594-repl-settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ object Test extends SessionTest {
| ^
|b: String
|
|scala> """
|scala> :quit"""
}
2 changes: 1 addition & 1 deletion test/files/run/t4671.check
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ println(s.mkString(""))
}


scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t4710.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ scala> def method : String = { implicit def f(s: Symbol) = "" ; 'symbol }
warning: there was one feature warning; re-run with -feature for details
method: String

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t5072.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ defined class C
scala> Thread.currentThread.getContextClassLoader.loadClass(classOf[C].getName)
res0: Class[_] = class C

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t5256d.check
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ scala.AnyRef {
def foo: scala.Nothing
}

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t5535.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ f: Int => Int = <function1>
scala> println(f(10))
11

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t5537.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ res2: List[scala.collection.immutable.List.type] = List()
scala> List[Set.type]()
res3: List[Set.type] = List()

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t5583.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ scala> for (i <- 1 to 10) {s += i}
scala> println(s)
165

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t5655.check
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ and import x
x
^

scala>
scala> :quit
2 changes: 1 addition & 1 deletion test/files/run/t5789.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ n: Int = 2
scala> () => n
res0: () => Int = <function0>

scala>
scala> :quit
Loading

0 comments on commit ed9cca8

Please sign in to comment.