Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Padding when trying to fill whole terminal. #856

Open
valerii15298 opened this issue Jan 9, 2024 · 1 comment
Open

Padding when trying to fill whole terminal. #856

valerii15298 opened this issue Jan 9, 2024 · 1 comment

Comments

@valerii15298
Copy link
Contributor

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

  • Windows 11

Terminal/Console

  • Windows Terminal(Powershell)
@Trombecher
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants