crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.23k stars 276 forks source link

Windows does not support horizontal scrolling #466

Open DependentAppearance0 opened 4 years ago

DependentAppearance0 commented 4 years ago

Describe the bug When reading events with read() and matching resize events resize events wont fire when resizing vertically.

To Reproduce This code demonstrates the problem

use crossterm::{cursor::MoveTo, event::read, ExecutableCommand, terminal::size};
use std::io::stdout;

fn main() {
    loop {
        let inpute = read().expect("");

        match inpute {
            crossterm::event::Event::Key(_) => {}
            crossterm::event::Event::Mouse(_) => {}
            crossterm::event::Event::Resize(a, b) => {
                stdout().execute(MoveTo(0,0)).expect("");
                println!("{} {}        ", a, b);
                let (x, y) = size().expect("");
                println!("{} {}        ", x, y);
            }
        }
    }
}

Using this code after changing the terminals size vertically and horizontally outputs

111 9001
111 33

The size given from size() gives the correct height but the size from the event is the buffers size. This means that while if only resizing horizontally the size is correct there is no way to detect the height changing using just events as the buffers height stays constant.

Expected behavior I expected Resize events to contain the size of the window but they contain the size of the buffer. This means that resizing horizontally works perfectly but vertical resizes aren't recognized as the buffers size doesn't change. This is made even more confusing because size() returns the windows size and not the buffers size.

OS I have only tested this on windows.

Terminal/Console I have tested and confirmed that this happens both on cmd and powershell.

pm100 commented 4 years ago

I have investigated this and it depends on the console being used. Although I cannot reproduce your exact issue.

Using 'old fashioned' windows console no event are generated for vertical resize. This is because windows does not consider these to be buffer resize events. As far as it is concerned making it smaller keeps the same buffer size but adds a scroll bar, making it larger simply does nothing. The old windows console is a PITA for any resize. In this case your test app does nothing, it does not know that any resizing is happening

The spiffy new Windows Terminal behaves correctly. So your test app works fine and displays the correct info.

Maybe this was a bug fix in windows terminal, was this what you are using?

Note that PDCurses reported the same issue and they have a work around which involves checking to see if the screen size changed from time to time

TimonPost commented 3 years ago

I fixed the wrong size return. Will make a PR soon.

TimonPost commented 3 years ago

it seems like this is a bug indeed. I don't see any events fired when resized horizontally.