Skip to content

Commit

Permalink
feat: add ClearDisplay event
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Aug 5, 2024
1 parent e064b64 commit 24c612a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,13 @@ 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 @@ -848,6 +855,10 @@ 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 @@ -1072,6 +1083,11 @@ 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
4 changes: 4 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ 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 Expand Up @@ -654,6 +657,7 @@ impl Display for ReedlineEvent {
ReedlineEvent::HistoryHintWordComplete => write!(f, "HistoryHintWordComplete"),
ReedlineEvent::CtrlD => write!(f, "CtrlD"),
ReedlineEvent::CtrlC => write!(f, "CtrlC"),
ReedlineEvent::ClearDisplay => write!(f, "ClearDisplay"),
ReedlineEvent::ClearScreen => write!(f, "ClearScreen"),
ReedlineEvent::ClearScrollback => write!(f, "ClearScrollback"),
ReedlineEvent::Enter => write!(f, "Enter"),
Expand Down
10 changes: 10 additions & 0 deletions src/painting/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,16 @@ 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<()> {
Expand Down

0 comments on commit 24c612a

Please sign in to comment.