4

I've started using sbt on cygwin, but had a problem that my typing would not echo in console.

Following this advice, sbt now echos, e.g.:

$ sbt
[info] Loading project definition from D:\cygwin\home\Administrator\scala-2.11.2\coursera\example\project\project
[info] Loading project definition from D:\cygwin\home\Administrator\scala-2.11.2\coursera\example\project
[info] Set current project to progfun-example (in build file:/D:/cygwin/home/Administrator/scala-2.11.2/coursera/example/)
> ; eval System.setProperty("jline.terminal", "scala.tools.jline.UnixTerminal")
[info] ans: java.lang.String = jline.UnixTerminal
> console
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.10.4 (Java HotSpot(TM) Client VM, Java 1.7.0_67).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import example.Lists._
import example.Lists._

scala> 

I tried to automate this fix by entering the line export SBT_OPTS="-Djline.terminal=scala.tools.jline.UnixTerminal" in ~/.sbtconfig, but I may not be using the correct syntax, as echoing doesn't seem to work.

How to get sbt console to use ; eval System.setProperty("jline.terminal", "scala.tools.jline.UnixTerminal") automatically?

Community
  • 1
  • 1
boardrider
  • 5,882
  • 7
  • 49
  • 86

1 Answers1

2

There's so much to discover in sbt...

> inspect initialize
[info] Setting: Unit = ()
[info] Description:
[info]  A convenience setting for performing side-effects during initialization.
[info] Provided by:
[info]  */*:initialize
[info] Defined at:
[info]  (sbt.Defaults) Defaults.scala:153
[info] Delegates:
[info]  *:initialize
[info]  {.}/*:initialize
[info]  */*:initialize
[info] Related:
[info]  */*:initialize

You can leverage initialize that's called for performing side-effects during initialization. With the following in ~/.sbt/0.13/default.sbt you could achieve executing System.setProperty:

initialize := {
  System.setProperty("jline.terminal", "scala.tools.jline.UnixTerminal")
}

When in sbt shell execute eval sys.props("jline.terminal") to check it out. It works fine in console (drop eval when calling sys.props).

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
  • Could you explain how does your suggestion automates? (As a Scala neubee) all I can understand is that I have to type something every-time I start sbt. Is my understanding wrong, and I can actually enter your suggestion in some sbt initialization file to have the action perform automatically when sbt starts? – boardrider Sep 22 '14 at 19:16
  • See my update to the answer. Open `~/.sbt/0.13/default.sbt` and copy the lines with `initialize`. Start `sbt`. – Jacek Laskowski Sep 22 '14 at 19:20
  • Could you explain how does your suggestion automates? (As a Scala neubee) If I understand you correctly, I need to create a build.sbt in each project, and put therein the line you suggests, viz.: $ cat build.sbt initialize := { System.setProperty("jline.terminal", "scala.tools.jline.UnixTerminal") } Doing so produces "[error] java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: scala.tools.jline.UnixTerminal" (and no echoing of typing) – boardrider Sep 23 '14 at 07:42
  • See https://github.com/jline/jline2/wiki/Terminal-Factory-Configuration where you can find possible values to control your terminal. – Jacek Laskowski Sep 23 '14 at 10:03
  • Thanks for you suggestion, @Jacek. However, for the time being I stopped using `sbt/scala`on `Cygwin` and cannot evaluate your solution: thus cannot green the `v` sign. – boardrider Sep 15 '15 at 11:17