picocli icon indicating copy to clipboard operation
picocli copied to clipboard

Interactive option is missing some keystrokes on Windows

Open rehand opened this issue 2 years ago • 7 comments

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

rehand avatar Mar 08 '24 09:03 rehand

Is this a picocli issue or a JLine issue?

remkop avatar Mar 08 '24 10:03 remkop

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

rehand avatar Mar 08 '24 12:03 rehand

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.

rehand avatar Mar 13 '24 13:03 rehand

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.

remkop avatar Mar 14 '24 02:03 remkop

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.

rehand avatar Mar 14 '24 07:03 rehand

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?

remkop avatar Apr 15 '24 01:04 remkop

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

rehand avatar Apr 15 '24 11:04 rehand