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

feat: impl ClearScreen with crossterm's Clear #813

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/painting/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,23 +510,18 @@ impl Painter {
/// Clear the screen by printing enough whitespace to start the prompt or
/// other output back at the first line of the terminal.
pub(crate) fn clear_screen(&mut self) -> Result<()> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lines calculation looks correct @sholderbach. But Warp has a sticky upper block that would hide the first few lines. I don't know how Warp's people implement their terminal and it looks terminal::size() returns the whole window including those hidden by the block.

self.stdout.queue(cursor::Hide)?;
let (_, num_lines) = terminal::size()?;
for _ in 0..2 * num_lines {
self.stdout.queue(Print("\n"))?;
}
self.stdout.queue(MoveTo(0, 0))?;
self.stdout.queue(cursor::Show)?;

self.stdout.flush()?;
self.stdout
.queue(Clear(ClearType::All))?
.queue(MoveTo(0, 0))?
.flush()?;
self.initialize_prompt_position(None)
}

pub(crate) fn clear_scrollback(&mut self) -> Result<()> {
self.stdout
.queue(crossterm::terminal::Clear(ClearType::All))?
.queue(crossterm::terminal::Clear(ClearType::Purge))?
.queue(cursor::MoveTo(0, 0))?
.queue(Clear(ClearType::All))?
.queue(Clear(ClearType::Purge))?
.queue(MoveTo(0, 0))?
.flush()?;
self.initialize_prompt_position(None)
}
Expand Down
Loading