Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit eab44dd

Browse files
committed
SI-9206 REPL custom continuation prompt
Because who doesn't want to customize their continuation prompt? `scala -Dscala.repl.continue="..."` looks especially nice with `-Dscala.color`. Somewhat works when pasting, but the test rig for running a transcript does not seek to support custom secondary prompts.
1 parent 2ceb09c commit eab44dd

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/repl/scala/tools/nsc/interpreter/ILoop.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
753753

754754
private object paste extends Pasted {
755755
import scala.util.matching.Regex.quote
756-
val ContinueString = " | "
756+
val ContinuePrompt = replProps.continuePrompt
757+
val ContinueString = replProps.continueText // " | "
757758
val PromptString = prompt.lines.toList.last
758759
val anyPrompt = s"""\\s*(?:${quote(PromptString.trim)}|${quote(AltPromptString.trim)})\\s*""".r
759760

@@ -797,7 +798,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
797798
echo("You typed two blank lines. Starting a new command.")
798799
None
799800
case IR.Incomplete =>
800-
in.readLine(paste.ContinueString) match {
801+
in.readLine(paste.ContinuePrompt) match {
801802
case null =>
802803
// we know compilation is going to fail since we're at EOF and the
803804
// parser thinks the input is still incomplete, but since this is
@@ -940,8 +941,9 @@ object ILoop {
940941
Console.withOut(ostream) {
941942
val output = new JPrintWriter(new OutputStreamWriter(ostream), true) {
942943
// skip margin prefix for continuation lines, unless preserving session text for test
944+
// should test for repl.paste.ContinueString or replProps.continueText.contains(ch)
943945
override def write(str: String) =
944-
if (!inSession && (str forall (ch => ch.isWhitespace || ch == '|'))) () // repl.paste.ContinueString
946+
if (!inSession && (str forall (ch => ch.isWhitespace || ch == '|'))) ()
945947
else super.write(str)
946948
}
947949
val input = new BufferedReader(new StringReader(code.trim + "\n")) {

src/repl/scala/tools/nsc/interpreter/ReplProps.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,17 @@ class ReplProps {
4545

4646
// Handy system prop for shell prompt, or else pick it up from compiler.properties
4747
val promptString = Prop[String]("scala.repl.prompt").option getOrElse (if (info) "%nscala %s> " else shellPromptString)
48-
def promptText = enversion(promptString)
49-
val prompt = {
50-
import scala.io.AnsiColor.{ MAGENTA, RESET }
51-
if (colorOk) s"$MAGENTA$promptText$RESET" else promptText
48+
val promptText = enversion(promptString)
49+
val prompt = encolor(promptText)
50+
51+
// Prompt for continued input, will be right-adjusted to width of the primary prompt
52+
val continueString = Prop[String]("scala.repl.continue").option getOrElse "| "
53+
val continueText = {
54+
val text = enversion(continueString)
55+
val margin = promptText.lines.toList.last.length - text.length
56+
if (margin > 0) " " * margin + text else text
5257
}
58+
val continuePrompt = encolor(continueText)
5359

5460
//def welcome = enversion(Prop[String]("scala.repl.welcome") or shellWelcomeString)
5561
def welcome = enversion {

0 commit comments

Comments
 (0)