Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the prompt of Scala REPL programatically?

I want to change the prompt of Scala REPL. I found out that I can change the prompt in power-mode like the following.

scala> 

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._, definitions._ also imported    **
** Try  :help, :vals, power.<tab>           **

scala> repl.setPrompt("\ncool prompt!> ")

cool prompt!> 

Now I want to do this in normal mode or initialCommands of sbt console. Does anyone know how to do this?

like image 626
tototoshi Avatar asked Mar 07 '13 10:03

tototoshi


People also ask

How do I get scala REPL from command prompt?

We can start Scala REPL by typing scala command in console/terminal.

What does the scala REPL stand for?

The Scala REPL (“Read-Evaluate-Print-Loop”) is a command-line interpreter that you use as a “playground” area to test your Scala code.

How does scala REPL work?

The scala command will execute a source script by wrapping it in a template and then compiling and executing the resulting program. In interactive mode, the REPL reads expressions at the prompt, wraps them in an executable template, and then compiles and executes the result.

Does scala have REPL?

Scala REPL is a command-line tool for the expression, evaluation, and execution of small code snippets. The acronym REPL stands for “Read-Evaluate-Print-Loop”. Similar to Java Shell, Scala REPL is very useful to newcomers and to those who want to experiment with new libraries or language features.


1 Answers

Scala 2.10.0

$intp.asInstanceOf[scala.tools.nsc.interpreter.ILoop$ILoopInterpreter]
     .getClass
     .getDeclaredField("$outer").get($intp)
     .asInstanceOf[scala.tools.nsc.interpreter.ILoop]
     .setPrompt("\ncool prompt!> ")
like image 193
Kenji Yoshida Avatar answered Nov 07 '22 05:11

Kenji Yoshida