nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
519 stars 144 forks source link

Key events are reported incorrectly #663

Open ClementNerma opened 10 months ago

ClementNerma commented 10 months ago

Environment: Windows 11 -> Windows Terminal -> WSL or PowerShell

When imlpement my own EditMode, I stumbled upon an issue: some key events are reported incorrectly.

Basically, I convert the event using ReedlineRawEvent::into() which gives me a crossterm::event::Event value.

If I press Ctrl + Backspace for instance, it will be reported as the w key pressed with the CONTROL modifier.

I tried to debug a little bit by modifying reedline's code and it seems like the event reedline gets from crossterm using crossterm::event::read() already contains the error, it is not caused by a faulty event conversion.

When running the event_listener example in this crate with cargo run --example event_listener, I get the correct code reported.

I tried putting a terminal::enable_raw_mode() just before the event reading, but it did not work. Maybe it needs to be set as soon as the program begins? But would that cause other troubles? I don't enough about terminals to answer this.

But this is a big problem as it makes handling some key combinations impossible. Also pressing Ctrl + Backspace and Ctrl +w return the exact same event, so it's not even possible to work around this problem using a little "hack" hashmap mapping the correct codes.

ClementNerma commented 1 month ago

I just found out it seems related to this still open crossterm issue: https://github.com/crossterm-rs/crossterm/issues/685