crossterm
crossterm copied to clipboard
Print command prints past the set terminal buffer size
Describe the bug The set size of the terminal is not respected when printing a string in a loop.
To Reproduce Using crossterm version 0.26.1, run the below code:
fn main() -> Result<()> {
let (initial_cols, initial_rows) = terminal::size()?;
execute!(stdout(),
terminal::EnterAlternateScreen,
terminal::SetSize(10, 80),
cursor::MoveTo(0, 0),
)?;
terminal::enable_raw_mode()?;
for _ in 0..3 {
execute!(stdout(),
cursor::MoveTo(0, 0),
Print("....................".to_string()),
cursor::MoveTo(0, 0),
)?;
std::thread::sleep(Duration::from_millis(1000));
}
terminal::disable_raw_mode()?;
execute!(stdout(),
cursor::MoveTo(0, 0),
terminal::SetSize(initial_cols, initial_rows),
terminal::LeaveAlternateScreen
)?;
Ok(())
}
I've also attempted various combinations of enabling line wrapping, not using raw mode, and not using an alternate screen, but that has not helped. I can also verify that the size of the terminal and cursor position is consistent for each loop.
I've also tried clearing the screen at the top of each loop, but curiously that makes loops 2 and 3 print nothing.
Expected behavior My expectation of the code I posted is that it should print this:
..........
..........
every loop given that I've specified a column count of 10. My actual output looks like this:
loop 1
..........
..........
loop 2,3
....................
..........
OS Windows 10 Version 10.0.19045 Build 19045
Terminal/Console Windows Terminal