jline / jline3

JLine is a Java library for handling console input.
Other
1.49k stars 218 forks source link

jline doesn't work on intellij on windows 10 #542

Closed ghandhikus closed 4 years ago

ghandhikus commented 4 years ago

Jline immediately after calling for readLine, throws EOF exception.

Gradle Imports

    compile group: 'org.jline', name: 'jline', version: '3.15.0'
    compile group: 'org.jline', name: 'jline-terminal-jna', version: '3.15.0'
    compile group: 'net.java.dev.jna', name: 'jna', version: '5.5.0'

Code

Logger.getLogger("org.jline").setLevel(Level.ALL);

Terminal terminal = TerminalBuilder.builder().jna(true).jansi(false).build();
System.out.println(terminal.getClass());

LineReader reader = LineReaderBuilder.builder()
        .terminal(terminal)
        .parser(new DefaultParser())
        .build();

while (true) {
    try {
        String line = reader.readLine("prompt > ");
        System.out.println(line);
    } catch (UserInterruptException e) {
        // Ignore
        return;
    } catch (EndOfFileException e) {
        e.printStackTrace();
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

Output

Jun 05, 2020 3:58:40 AM org.jline.utils.Log logr
WARNING: Creating a dumb terminal
java.lang.IllegalStateException: Unable to create a system terminal
    at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:317)
    at org.jline.terminal.TerminalBuilder.build(TerminalBuilder.java:263)
    at main.Main.main(Main.java:27)
    Suppressed: com.sun.jna.LastErrorException: [6] The handle is invalid.
        at com.sun.jna.Native.invokeVoid(Native Method)
        at com.sun.jna.Function.invoke(Function.java:415)
        at com.sun.jna.Function.invoke(Function.java:361)
        at com.sun.jna.Library$Handler.invoke(Library.java:265)
        at org.jline.terminal.impl.jna.win.$Proxy0.GetConsoleMode(Unknown Source)
        at org.jline.terminal.impl.jna.win.JnaWinSysTerminal.createTerminal(JnaWinSysTerminal.java:40)
        at org.jline.terminal.impl.jna.JnaSupportImpl.winSysTerminal(JnaSupportImpl.java:39)
        at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:326)
        ... 2 more
class org.jline.terminal.impl.DumbTerminal
prompt > 
org.jline.reader.EndOfFileException
    at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:639)
    at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:454)
    at main.Main.main(Main.java:36)

Tried on two IntelliJ versions

IntelliJ IDEA 2020.1.2 (Community Edition)
Build #IC-201.7846.76, built on June 1, 2020
Runtime version: 11.0.7+10-b765.53 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 16
Registry: ide.tooltip.initialDelay=299
Non-Bundled Plugins: com.intellij.plugins.xwinkeymap, indent-rainbow.indent-rainbow
IntelliJ IDEA 2019.3.1 (Community Edition)
Build #IC-193.5662.53, built on December 18, 2019
Runtime version: 11.0.5+10-b520.17 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 725M
Cores: 16
Registry: ide.tooltip.initialDelay=299
Non-Bundled Plugins: indent-rainbow.indent-rainbow
ghandhikus commented 4 years ago

https://github.com/jline/jline3/blob/04eaadf4b532a9926d89476ebcf0f70964a86346/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java#L639

mattirn commented 4 years ago

@ghandhikus, I have copied your code above and run it successfully on IntelliJ version

IntelliJ IDEA 2020.1.3 (Community Edition)
Build #IC-201.8538.31, built on July 7, 2020
Runtime version: 11.0.7+10-b765.64 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 725M
Cores: 4