From 9f33d5ef64b6ff84483dea00aab6760478b7c5db Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 7 Aug 2024 08:37:32 +0800 Subject: [PATCH] take 2 - reimpl clear_screen Signed-off-by: tison --- src/engine.rs | 16 ---------------- src/enums.rs | 3 --- src/painting/painter.rs | 29 +++++++---------------------- 3 files changed, 7 insertions(+), 41 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index c958a73a..3c4fa2a0 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -666,13 +666,6 @@ impl Reedline { self.painter.paint_line(msg) } - /// - 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<()> { @@ -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) @@ -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()?; diff --git a/src/enums.rs b/src/enums.rs index 75324b6b..654e9cb9 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -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, diff --git a/src/painting/painter.rs b/src/painting/painter.rs index f0f6234c..92c1af4c 100644 --- a/src/painting/painter.rs +++ b/src/painting/painter.rs @@ -507,36 +507,21 @@ impl Painter { self.stdout.flush() } - /// - 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) }