2013-03-07 47 views
9

我想更改Scala REPL的提示。我发现我可以像下面这样改变power-mode的提示。是否有可能以编程方式更改Scala REPL的提示?

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!> 

现在,我想这样做,在正常模式下或SBT控制台initialCommands。有谁知道如何做到这一点?

+2

FYI http://www.scala-sbt.org/release/docs/Howto/interactive.html#prompt – 2013-03-07 10:59:39

+1

谢谢,但我想改变的是提示的Scala REPL,而不是sbt交互式shell的提示。 – tototoshi 2013-03-07 12:18:27

+0

@totoshi对不起,我误解了你的问题在控制台部分。 – 2013-03-07 12:35:39

回答

8

斯卡拉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!> ") 
+0

哇!有用!谢谢。 – tototoshi 2013-03-07 14:27:11

+0

这段代码在REPL启动后工作良好,但当我将它添加到sbt console的initialCommands时无法编译。在REPL完全启动之前无法看到$ intp值。有另一种方法来访问$ intp值吗? – tototoshi 2013-03-07 14:59:36

+0

对于漂亮的代码布局+1! – 2013-03-07 16:16:53

相关问题