remkop / picocli

Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
https://picocli.info
Apache License 2.0
4.8k stars 414 forks source link

Interactive option is missing some keystrokes on Windows #2222

Closed rehand closed 2 months ago

rehand commented 4 months ago

Hello, I've the problem that if one command has more than one interactive input (e.g. due to interactive options or using System.console().readLine() in the option) that starting with the second input the first entered character is captured by the console (from jline3) itself, but not by the input reader. This is very annoying and confusing when entering passwords (echo = false) because then you don't notice that the first character is lost.

I've added a demo project which reproduces the issue.

The issue occurs only on Windows, I wasn't able to reproduce it on Linux. It also works on Windows using Ubuntu Bash via WSL2.

My example has two interactive options and it also asks via "System.console().readLine()". For each option I'm typing "test". After entering all 4 options you can see, that jline3 captured 3 times "t", so the missing characters.

prompt> cmd option1 option2
Enter value for option1: test
Enter value for option2: est
Enter value for input1: est
Enter value for input2: est
Option 1: test
Option 2: est
Input 1: est
Input 2: est
prompt> ttt

I'd appreciate any help on this issue. It looks related to 1139

testJline3.zip

remkop commented 4 months ago

Is this a picocli issue or a JLine issue?

rehand commented 4 months ago

Could also be a JLine issue, but in general interactive options are broken when using "picocli-shell-jline3"

rehand commented 4 months ago

I've tried to recreate the issue with plain JLine3 and it also happens there, but only if System.console() is used for input. When using the lineReader it doesn't happen.

remkop commented 4 months ago

I've tried to recreate the issue with plain JLine3 and it also happens there, but only if System.console() is used for input. When using the lineReader it doesn't happen.

The lineReader is a JLine class?

It may be tricky to change picocli to use a JLine class instead of System.console() for interactive options.

rehand commented 4 months ago

Yes, it's org.jline.reader.LineReader

I'm using now the following workaround: If line reader is available (through CDI) then I'm using line reader, if not, a fallback to System.console() is implemented.

remkop commented 2 months ago

In your workaround, you stopped using picocli interactive options?

I am wondering if there is anything I can/should do for this issue. One idea is to update the documentation to tell users that interactive options cannot be combined with JLine3. Or, if there is a workaround, to explain this workaround in the picocli documentation for interactive options. What do you think?

rehand commented 2 months ago

I do use interactive options but I'm resolving them myself via a mixin and then by using the LineReader from JLine.

I also reported the bug to jline3