Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console input within SBT does not echo to the screen

Tags:

sbt

I hope I am missing something as it seems that keystrokes do not echo to the screen when a program is run within sbt. Here is an example:

object ConsoleTest extends App {
  println("Enter a line:")
  val input = Console.readLine()
  println("You entered: " + input)
}

When I compile this simple code and run it from the command line (outside of sbt), I see the keystrokes as I type them for input and all works fine.
Unfortunately, when I use sbt to compile & run the same code, it does not echo the keystrokes to the screen at all. This is a disconcerting experience.
Has anyone else experienced this difference?
I've done some searching to see if others encounter this and whether there might be an sbt runtime parameter to allow keystroke echo. No luck so far.
I am using sbt-0.13.2 and the Java version of the above code experiences this same difference so it seems localized to running in the sbt environment.
Any insight is appreciated.

like image 870
Wiz Schard Avatar asked May 12 '14 14:05

Wiz Schard


1 Answers

This question is 2.5 years old, still no answer, so here goes :)

I tested with Windows 10, using Scala 2.12.1, SBT 0.13.13.1. The test program worked fine under Cmd and WSL's bash.

Historically this problem has been symptomatic of a JLine issue. You can override the JLine setting with the jline.terminal Java system variable to values like auto, none and windows. Here are the complete docs.

Here are some examples of how to specify various settings:

C:\work\experiments\sbt\optionTest>sbt run
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from C:\work\experiments\sbt\optionTest\project
[info] Updating {file:/C:/work/experiments/sbt/optionTest/project/}optiontest-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to change-me (in build file:/C:/work/experiments/sbt/optionTest/)
[warn] there was one deprecation warning (since 2.11.0); re-run with -deprecation for details
[warn] one warning found
Enter a line:
asdf
You entered: asdf
[success] Total time: 46 s, completed Jan 7, 2017 1:27:27 PM

C:\work\experiments\sbt\optionTest> sbt "-Djline.terminal=none" run
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from C:\work\experiments\sbt\optionTest\project
[info] Set current project to change-me (in build file:/C:/work/experiments/sbt/optionTest/)
Enter a line:
asdf
You entered: asdf
[success] Total time: 3 s, completed Jan 7, 2017 1:28:12 PM

C:\work\experiments\sbt\optionTest> sbt "-Djline.terminal=windows" run
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from C:\work\experiments\sbt\optionTest\project
[info] Set current project to change-me (in build file:/C:/work/experiments/sbt/optionTest/)
Enter a line:
asdf
You entered: asdf
[success] Total time: 3 s, completed Jan 7, 2017 1:28:26 PM
like image 108
Mike Slinn Avatar answered Oct 16 '22 03:10

Mike Slinn