Skip to content

Commit

Permalink
take 2 - reimpl clear_screen
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Aug 7, 2024
1 parent 24c612a commit 9f33d5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 41 deletions.
16 changes: 0 additions & 16 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,6 @@ impl Reedline {
self.painter.paint_line(msg)
}

/// <placeholder docs>
pub fn clear_display(&mut self) -> Result<()> {
self.painter.clear_display()?;

Ok(())
}

/// Clear the screen by printing enough whitespace to start the prompt or
/// other output back at the first line of the terminal.
pub fn clear_screen(&mut self) -> Result<()> {
Expand Down Expand Up @@ -855,10 +848,6 @@ impl Reedline {
self.input_mode = InputMode::Regular;
Ok(EventStatus::Exits(Signal::CtrlC))
}
ReedlineEvent::ClearDisplay => {
self.painter.clear_display()?;
Ok(EventStatus::Handled)
}
ReedlineEvent::ClearScreen => {
self.painter.clear_screen()?;
Ok(EventStatus::Handled)
Expand Down Expand Up @@ -1083,11 +1072,6 @@ impl Reedline {
self.editor.reset_undo_stack();
Ok(EventStatus::Exits(Signal::CtrlC))
}
ReedlineEvent::ClearDisplay => {
self.deactivate_menus();
self.painter.clear_display()?;
Ok(EventStatus::Handled)
}
ReedlineEvent::ClearScreen => {
self.deactivate_menus();
self.painter.clear_screen()?;
Expand Down
3 changes: 0 additions & 3 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,6 @@ pub enum ReedlineEvent {
/// Bubble up [`Signal::CtrlC`]
CtrlC,

/// Clears the display and set prompt to first line
ClearDisplay,

/// Clears the screen and sets prompt to first line
ClearScreen,

Expand Down
29 changes: 7 additions & 22 deletions src/painting/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,36 +507,21 @@ impl Painter {
self.stdout.flush()
}

/// <placeholder docs>
pub(crate) fn clear_display(&mut self) -> Result<()> {
self.stdout.queue(cursor::Hide)?;
self.stdout.queue(Clear(ClearType::All))?;
self.stdout.queue(MoveTo(0, 0))?;
self.stdout.queue(cursor::Show)?;
self.stdout.flush()?;
self.initialize_prompt_position(None)
}

/// 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<()> {
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::Purge))?
.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

0 comments on commit 9f33d5e

Please sign in to comment.