Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/repl-frontend/scala/tools/nsc/interpreter/shell/ILoop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,15 @@ class ILoop(config: ShellConfig, inOverride: BufferedReader = null,
def replay(): Unit = {
if (replayCommandStack.isEmpty)
echo("Nothing to replay.")
else for (cmd <- replayCommands) {
echo("Replaying: " + cmd) // flush because maybe cmd will have its own output
command(cmd)
echo("")
else {
val reprompt = "replay> "
intp.reporter.indenting(reprompt.length) {
for (cmd <- replayCommands) {
echo(s"$reprompt$cmd")
command(cmd)
echo("") // flush because maybe cmd will have its own output
}
}
}
}
/** `reset` the interpreter in an attempt to start fresh.
Expand Down Expand Up @@ -856,7 +861,7 @@ class ILoop(config: ShellConfig, inOverride: BufferedReader = null,
result
}

private val continueText = {
private val continueText = {
val text = enversion(continueString)
val margin = promptText.linesIterator.toList.last.length - text.length
if (margin > 0) " " * margin + text else text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ class ReplReporterImpl(val config: ShellConfig, val settings: Settings = new Set
flush()
}

private def indentDepth: Int = config.promptText.linesIterator.toList.last.length
private[this] var indentation: String = " " * indentDepth
def indenting(n: Int)(body: => Unit): Unit = {
val save = indentation
indentation = " " * n
try body finally indentation = save
}
private def indented(str: String) = str.linesIterator.mkString(indentation, "\n" + indentation, "")

def colorOk: Boolean = config.colorOk
def indentDepth: Int = config.promptText.linesIterator.toList.last.length
def isDebug: Boolean = config.isReplDebug
def isTrace: Boolean = config.isReplTrace

Expand Down Expand Up @@ -152,9 +160,6 @@ class ReplReporterImpl(val config: ShellConfig, val settings: Settings = new Set
printMessage(pos, prefix + msg)
}

private val indentation = " " * indentDepth
private def indented(str: String) = str.linesIterator.mkString(indentation, "\n" + indentation, "")

// indent errors, error message uses the caret to point at the line already on the screen instead of repeating it
// TODO: can we splice the error into the code the user typed when multiple lines were entered?
// (should also comment out the error to keep multi-line copy/pastable)
Expand Down
3 changes: 3 additions & 0 deletions src/repl/scala/tools/nsc/interpreter/Interface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ trait ReplReporter extends Reporter {
*/
def withoutUnwrapping(body: => Unit): Unit

/** Change indentation due to prompt. */
def indenting(n: Int)(body: => Unit): Unit


/** Print result (Right --> success, Left --> error)
*/
Expand Down
12 changes: 12 additions & 0 deletions test/files/run/repl-replay.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

scala> locally { val x = 42 ; "$x" }
res0: String = $x

scala> :replay -Xlint
replay> locally { val x = 42 ; "$x" }
^
warning: possible missing interpolator: detected interpolated identifier `$x`
res0: String = $x


scala> :quit
9 changes: 9 additions & 0 deletions test/files/run/repl-replay.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import scala.tools.partest.ReplTest

object Test extends ReplTest {
override def code = """
|locally { val x = 42 ; "$x" }
|:replay -Xlint
""".stripMargin.trim
}