crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.29k stars 280 forks source link

Panic in parse_csi_sgr_mouse #835

Open Timmmm opened 1 year ago

Timmmm commented 1 year ago

If you enable pixel mouse position reporting like this:

stdout.write_all(b"\x1B[?1016h").unwrap();

Then it works fine except if you move your mouse to the top of the screen, then it can report 0, and that causes this code to panic:

    // See http://www.xfree86.org/current/ctlseqs.html#Mouse%20Tracking
    // The upper left character position on the terminal is denoted as 1,1.
    // Subtract 1 to keep it synced with cursor
    let cx = next_parsed::<u16>(&mut split)? - 1;
    let cy = next_parsed::<u16>(&mut split)? - 1;

Because 0 - 1 underflows. Simple hack: use saturating subtract. I suspect nobody is going to care about the difference between pixel 0 and 1.

OS Linux

Terminal/Console Kitty