crossterm-rs / crossterm

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

Padding when trying to fill whole terminal. #856

Open valerii15298 opened 8 months ago

valerii15298 commented 8 months ago

Describe the bug For some reason crossterm does not fill whole terminal with color(see padding on right and on the bottom), even though I added more rows +100(check the code below) but it does not affect anything: image

To Reproduce Just execute this code:

use crossterm::style::Stylize;
use crossterm::terminal::{
    disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
};
use crossterm::{execute, ExecutableCommand};
use std::io::stdout;
use std::time::Duration;
use std::{io, thread};

fn main() -> io::Result<()> {
    enable_raw_mode()?;
    let mut stdout = stdout();
    execute!(
        stdout,
        EnterAlternateScreen,
        crossterm::terminal::Clear(crossterm::terminal::ClearType::All),
        crossterm::cursor::MoveTo(0, 0),
        crossterm::cursor::Hide
    )?;
    let (columns, rows) = crossterm::terminal::size()?;
    let content = (" ".repeat(columns as usize) + "\n").repeat(rows as usize + 100);
    println!("{}", content.on(crossterm::style::Color::Red));
    execute!(
        stdout,
        crossterm::cursor::MoveTo(0, 0),
        crossterm::cursor::Hide
    )?;
    // println!("{columns}, {rows}");
    thread::sleep(Duration::from_secs(2));

    stdout.execute(LeaveAlternateScreen)?;
    disable_raw_mode()?;
    Ok(())
}

Expected behavior A clear and concise description of what you expected to happen.

OS

Terminal/Console

Trombecher commented 5 months ago

Your println!(...) statement prints an additional line feed to the terminal. The printed string would look something like this: ....\n\n. But because you are at the bottom of the screen and want to insert a new line, Powershell scrolls the whole content up by a line and therefore creating this last empty line. Instead of println!(...) you could use PrintStyledContent(...) like this

execute!(
    stdout,
    PrintStyledContent(content.on(Color::Red)),
);

and it works as expected.