crossterm-rs / crossterm

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

Fix panic on 0 size terminal on windows #946

Closed maciek50322 closed 4 days ago

maciek50322 commented 5 days ago

Found bug on windows working with ratatui, with everything default, no drawing, just waiting for event.

When BOTH of terminal width & height are changed to 0 (like on image)
image there seems to be record.size.y == -1, because record.size.y as u16 + 1 panics with

thread 'main' panicked at C:\...\crossterm-0.28.1\src\event\source\windows.rs:70:33:
attempt to add with overflow
-1i16 as u16 == u16::MAX
u16::MAX + 1 // panics

used as i32 for -1 to become 0 (represents size of terminal better than 65535) and i16::MAX (32767) to become 32768