tokio-rs / console

a debugger for async rust!
MIT License
3.6k stars 142 forks source link

Key presses happen twice on Windows #514

Open sunrosa opened 9 months ago

sunrosa commented 9 months ago

What crate(s) in this repo are involved in the problem?

tokio-console

What is the issue?

Whenever pressing a key in the tokio-console ui, it presses twice. Pressing j goes down two elements. Pressing space pauses then unpauses. Both keys press instantly. It doesn't matter when I release the key.

How can the bug be reproduced?

Run tokio-console on Windows 10 (or Windows 11, apparently) on Powershell or Git Bash. The bug happened on the Tabby terminal emulator and on the VSCode terminal emulator.

Logs, error output, etc

No response

Versions

console-subscriber v0.2.0 console-api v0.6.0

tokio-console 0.1.10

Possible solution

I remember seeing somewhere that Windows key events fire on both key pressed and key released, while Unix key events only fire on key pressed. It may be the other way around.

Additional context

No response

Would you like to work on fixing this bug?

maybe

hawkw commented 9 months ago

Interesting, thanks for the report! I wonder if there's something we can enable in crossterm/ratatui to make its key event behavior on Windows consistent with other platforms?

If not, we could certainly implement some windows-specific logic to work around this in the console. But, it seems like there ought to be something in the terminal UI libraries for it...

damccull commented 8 months ago

I'm also having this issue. Windows 11 New terminal app nushell

damccull commented 8 months ago

For me, #515 fixes this problem.

joshka commented 8 months ago

Interesting, thanks for the report! I wonder if there's something we can enable in crossterm/ratatui to make its key event behavior on Windows consistent with other platforms?

Ratatui doesn't have anything that handles the actual key events, the code for this is all in Crossterm. In Crossterm, there's an open issue to put the KeyPress events behind a feature flag, as it caught a number of people off guard (and makes upgrading apps from 0.26 to 0.27 kinda annoying). Until then it's pretty easy to check for event.kind == KeyEventKind::Press instead.