Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sbt console fails to load terminal - Invalid terminal type: jline.UnixTerminal #562

Closed
bmjsmith opened this issue Oct 8, 2012 · 28 comments
Assignees
Labels
Milestone

Comments

@bmjsmith
Copy link

bmjsmith commented Oct 8, 2012

I'm running "sbt console" using 0.12.0 under cygwin on windows with scala 2.9.2, jdk 1.6.0_25.

I'm using the shell script supplied as part of the MSI, and TERM=xterm.

I get this output, and the terminal is fairly non functional (no local echo, ^D doesn't exit).

$ sbt console
Getting net.java.dev.jna jna 3.2.3 ...
:: retrieving :: org.scala-sbt#boot-jna
confs: [default]
1 artifacts copied, 0 already retrieved (838kB/125ms)
Getting org.scala-sbt sbt 0.12.0 ...
:: retrieving :: org.scala-sbt#boot-app
confs: [default]
40 artifacts copied, 0 already retrieved (8158kB/5419ms)
Getting Scala 2.9.2 (for sbt)...
:: retrieving :: org.scala-sbt#boot-scala
confs: [default]
4 artifacts copied, 0 already retrieved (20090kB/3389ms)
[info] Loading project definition from D:\workspace\scalaz-example-sbt\project
[info] Set current project to scalaz-example-sbt (in build file:/D:/workspace/scalaz-example-sbt/)
[info] Starting scala interpreter...
[info]
[ERROR] Failed to construct terminal; falling back to unsupportedjava.lang.IllegalArgumentException: Invalid terminal type: jline.UnixTerminal
at scala.tools.jline.TerminalFactory.create(TerminalFactory.java:83)
at scala.tools.jline.TerminalFactory.get(TerminalFactory.java:154)
at scala.tools.jline.console.ConsoleReader.(ConsoleReader.java:87)
at scala.tools.jline.console.ConsoleReader.(ConsoleReader.java:134)
at scala.tools.nsc.interpreter.JLineReader$JLineConsoleReader.(JLineReader.scala:42)
at scala.tools.nsc.interpreter.JLineReader.(JLineReader.scala:21)
at scala.tools.nsc.interpreter.ILoop.chooseReader(ILoop.scala:777)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:796)
at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:851)
at xsbt.ConsoleInterface.run(ConsoleInterface.scala:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:73)
at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:64)
at sbt.Console.console0$1(Console.scala:23)
at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24)
at sbt.TrapExit$.executeMain$1(TrapExit.scala:33)
at sbt.TrapExit$$anon$1.run(TrapExit.scala:42)
Caused by: java.lang.ClassCastException: jline.UnixTerminal cannot be cast to scala.tools.jline.Terminal
at scala.tools.jline.TerminalFactory.create(TerminalFactory.java:80)
... 19 more
Welcome to Scala version 2.9.2 (Java HotSpot(TM) Client VM, Java 1.6.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala>

This seems to be an incompatibility between a jline.jar containing scala.tools.jline at ~/.sbt/boot/scala-2.9.2/lib/jline.jar and one containing plain ole jline at ~/.sbt/boot/scala-2.9.2/org.scala-sbt/sbt/0.12.0/jline-1.0.jar.

If I delete the former, I get the same as issue #504. If I wipe ~/.sbt/boot as mentioned in 504, sbt downloads it all again.

Any workaround gratefully received.

@bmjsmith
Copy link
Author

Just to note, this is still a problem in 0.12.2.

@mbrambley
Copy link

im having this issue also... is there at least any workaround?

@bmjsmith
Copy link
Author

I haven't found one I like I'm afraid. You can run sbt under DOS. I tried finding a way to pass -Djline.terminal=scala.tools.jline.UnixTerminal through to console but couldn't get that to work.

@mbrambley
Copy link

can we get anyone to look at this? surely it would make it nicer for everyone if sbt worked in cygwin

@jsuereth
Copy link
Member

Sorry, I've been fighting this for a long time. It's actually a pretty annoying problem with various versions of jline. We're paying attention and trying to fix this, but having issues.

@jsuereth
Copy link
Member

Ok, I think I have a fix for the MSI, but I'm having issues using cygwin/terminal with the BACKSPACE button getting destroyed in the REPL. Still some kind of odd jline/jansi versioning madness.

@bmjsmith
Copy link
Author

Thanks Josh - if you want someone to test this let me know which build is in and I'll give it a spin.

@jsuereth
Copy link
Member

FYI - sbt/sbt-launcher-package#47

That's the result of my morning's debugging. Hopefully I can hammer some more in here.

@harrah
Copy link
Member

harrah commented Jun 22, 2013

Possibly fixed by 1a3ea6f. Verification pending.

@mbrambley
Copy link

gents im just an sbt user how can i try this fix/file as i cannot even find Launch.scala in my installation?
thanks

@harrah
Copy link
Member

harrah commented Jun 24, 2013

Launch.scala is an sbt source file. You can either build sbt from source (see CONTRIBUTING) or wait for 0.13.0-RC1, which might be out later this week.

@jsuereth
Copy link
Member

Ok, so here's a quick analysis of the issues.

FIRST ->
JLine has issues detecting cygwin. This means we have to manually pass in the jline.Terminal setting when in cygwin using a wrapper script (combined with stty hooks, thanks to cygwin's strange environment and lack of direct cygwin hooks in jline, for good reason).
See jline/jline2#62
*Note: this workaround is the common solution for most jline cygwin users. I'll update the docs appropriately for cygwin users, and the native packages have already had this fix for a while. *

SECOND ->
JLine 1.x -> 2.x adapted the jline.Terminal setting so that you can pass just "unix" or "windows" instead of a class name. THis is only valid in Jline 2.x, and not in 1.x. For sbt < 0.13, it uses jline 1.x, so must pass a fully qualified classname of which terminal to use. Scala + sbt 0.13 both use JLine 2.x, so they can just pass "unix" as the parameter and be done.

THIRD ->
Scala shades the jline library (places it under a scala.jline package). However it does not shade the jline.terminal option NOR does it provide a hook such that unshaded jline class references work within it. I consider this a bug in the shading.

SO for 0.12.x we really have no solution to this problem. Starting in 0.13, we'll have the scripts specify the terminal as =unix. I just verified that this works beautifully. For 0.12.x I see one of a few options:

  1. Disable jline when running in cygwin by default.
  2. Use -Djline.terminal=jline.UnixTerminal and wait for scala to fix their shaded jline.
  3. Leave the scala console broken under cygwin.

I'm going to report the issue against Scala's code-base, and elicit some feedback on how we want to proceed.

@jsuereth
Copy link
Member

Note: Scala JLine bug reported: https://issues.scala-lang.org/browse/SI-7604

@harrah
Copy link
Member

harrah commented Jun 24, 2013

Awesome, thanks Josh. The main action items for 0.13.0-RC1 are to update the setup docs for manual setup, update the changes page to notify users of the potential for improvement by using `-Djline.terminal=unix, and make the native packages to do the right thing by default.

@jsuereth
Copy link
Member

Yeah, already have the patches ready for native packages, I'll work on the docs after I figure out this JANSI issue.

harrah added a commit that referenced this issue Jun 26, 2013
The startup script should set sbt.cygwin=true if running from cygwin.
This will set the terminal type properly for JLine if not already set.
If sbt.cygwin=false or unset and os.name includes "windows", JAnsi is
downloaded by the launcher and installed on standard out/err.

The value for jline.terminal is transformed from explicit jline.X to
the basic types "windows", "unix", or "none".  Now that sbt uses JLine
2.0, these types are understood by both sbt's JLine and Scala's.
Older Scala versions shaded the classes but not the terminal property
so both couldn't be configured with a class name at the same time.
@harrah harrah closed this as completed in 1048976 Jun 26, 2013
@sourcedelica
Copy link

Hi guys - would one of you mind to add answer to http://stackoverflow.com/questions/17124689/i-really-would-like-sbt-and-its-console-to-work-under-cygwin-any-way-you-think-i giving the status? I was wondering which version of sbt and Scala repl will have the fix and if there any workarounds for now. Thanks!

@jsuereth
Copy link
Member

sbt 0.13 will have the fix, and will work with any Scala version AFAIK. The backspace will most likely still be broken. We're not sure what that issue is, but there's a fix for Scala 2.11 that may fix this issue as well.

@sourcedelica
Copy link

Thanks - that's good to know. The backspace is my primary source of pain.

@harrah
Copy link
Member

harrah commented Jun 26, 2013

It is probably clear in the context of this bug, but that is backspace in the Scala REPL on mintty/cygwin that will be broken. Other windows terminals (that don't require UnixTerminal) should work ok, including backspace.

@sourcedelica
Copy link

Ok. Are there any other terminals for Cygwin that support cut and paste? I realize this question is out of scope for this fix :) I'm coming from Mac and Cygwin is a necessary evil.

@sourcedelica
Copy link

I'm going to try rxvt when I get back to work.

@harrah
Copy link
Member

harrah commented Jun 26, 2013

I don't know much about windows options other than what I've done to help reproduce and fix this bug. I believe other terminals are limited in some way on earlier sbt versions, perhaps lacking color and shortcut support.

@bmjsmith
Copy link
Author

Just as an update. Using 0.13 RC 5 on mintty/cygwin/win8 and everything works like a charm, cut'n'paste and backspace in the sbt shell and in the scala console included. Thanks all for fixing this, much appreciated.

@mbrambley
Copy link

not for me... backspace woks in sbt now but still does nothing in the scala console
am i missing something? (just installed 13.5 tonight)

@bmjsmith
Copy link
Author

If you're using mintty, try enabling "Backspace sends ^H" in the terminal options under Keys. If that doesn't do the trick, check that ^H is recognised as the erase character by running stty from the bash prompt.

@mbrambley
Copy link

that did it thanks!!
"backspace sends ^H"

@jsuereth
Copy link
Member

This backspace send ^H setting sounds like something that belongs in our FAQs or documentation. Would either of you mind contributing to the place you would most likely have found the information besides the bug request :)

Thanks, and glad this works!

@bmjsmith
Copy link
Author

Josh - I'm not massively github savvy so let me know if I've done that wrong.

harrah pushed a commit that referenced this issue Sep 7, 2013
Added note about setting in mintty to force sending of ^H which is necessary for the scala console backspace to work when jline.UnixTerminal is set and stty erase is ^H.  Additional documentation for #562.
harrah pushed a commit that referenced this issue Sep 7, 2013
Added note about setting in mintty to force sending of ^H which is necessary for the scala console backspace to work when jline.UnixTerminal is set and stty erase is ^H.  Additional documentation for #562.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants