From fbcc1c341a5ae5765241573e2add0039d9905c43 Mon Sep 17 00:00:00 2001 From: sholderbach Date: Mon, 12 Sep 2022 21:57:43 +0200 Subject: [PATCH 1/3] Revert "remove anims and resize repaint (#451)" This reverts commit 59f7144d721cd573f629048e753f163f2652334f. --- src/engine.rs | 18 ++++++++++++++++-- src/painting/painter.rs | 7 +++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 747a05c3..9e434114 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -114,6 +114,9 @@ pub struct Reedline { hinter: Option>, hide_hints: bool, + // Is Some(n) read_line() should repaint prompt every `n` milliseconds + animate: bool, + // Use ansi coloring or not use_ansi_coloring: bool, @@ -168,6 +171,7 @@ impl Reedline { hinter, hide_hints: false, validator, + animate: false, use_ansi_coloring: true, menus: Vec::new(), buffer_editor: None, @@ -250,6 +254,14 @@ impl Reedline { self } + /// A builder which enables or disables animations/automatic repainting of prompt. + /// If `repaint` is true, every second the prompt will be repainted and the clock updates + #[must_use] + pub fn with_animation(mut self, repaint: bool) -> Self { + self.animate = repaint; + self + } + /// A builder that configures the highlighter for your instance of the Reedline engine /// # Example /// ```rust @@ -504,6 +516,8 @@ impl Reedline { if let Some(ec) = last_edit_commands { reedline_events.push(ReedlineEvent::Edit(ec)); } + } else if self.animate && !self.painter.exceeds_screen_size() { + reedline_events.push(ReedlineEvent::Repaint); }; for event in reedline_events.drain(..) { @@ -596,7 +610,7 @@ impl Reedline { ReedlineEvent::Mouse => Ok(EventStatus::Handled), ReedlineEvent::Resize(width, height) => { self.painter.handle_resize(width, height); - Ok(EventStatus::Inapplicable) + Ok(EventStatus::Handled) } ReedlineEvent::Repaint => { // A handled Event causes a repaint @@ -881,7 +895,7 @@ impl Reedline { ReedlineEvent::OpenEditor => self.open_editor().map(|_| EventStatus::Handled), ReedlineEvent::Resize(width, height) => { self.painter.handle_resize(width, height); - Ok(EventStatus::Inapplicable) + Ok(EventStatus::Handled) } ReedlineEvent::Repaint => { // A handled Event causes a repaint diff --git a/src/painting/painter.rs b/src/painting/painter.rs index 97df0a88..a3d52138 100644 --- a/src/painting/painter.rs +++ b/src/painting/painter.rs @@ -81,6 +81,13 @@ impl Painter { self.screen_height() - self.prompt_start_row } + /// Check if the currently painted content exceeds the size of the screen + /// and thus should not be repainted without reason (disable animation + /// repaint) + pub(crate) fn exceeds_screen_size(&self) -> bool { + self.large_buffer + } + /// Sets the prompt origin position and screen size for a new line editor /// invocation /// From 1f127089774514777af6228c1e80b2b9afc66976 Mon Sep 17 00:00:00 2001 From: sholderbach Date: Mon, 12 Sep 2022 22:00:08 +0200 Subject: [PATCH 2/3] Remove animations again --- src/engine.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 9e434114..b97bab33 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -114,9 +114,6 @@ pub struct Reedline { hinter: Option>, hide_hints: bool, - // Is Some(n) read_line() should repaint prompt every `n` milliseconds - animate: bool, - // Use ansi coloring or not use_ansi_coloring: bool, @@ -171,7 +168,6 @@ impl Reedline { hinter, hide_hints: false, validator, - animate: false, use_ansi_coloring: true, menus: Vec::new(), buffer_editor: None, @@ -254,14 +250,6 @@ impl Reedline { self } - /// A builder which enables or disables animations/automatic repainting of prompt. - /// If `repaint` is true, every second the prompt will be repainted and the clock updates - #[must_use] - pub fn with_animation(mut self, repaint: bool) -> Self { - self.animate = repaint; - self - } - /// A builder that configures the highlighter for your instance of the Reedline engine /// # Example /// ```rust @@ -516,7 +504,7 @@ impl Reedline { if let Some(ec) = last_edit_commands { reedline_events.push(ReedlineEvent::Edit(ec)); } - } else if self.animate && !self.painter.exceeds_screen_size() { + } else if !self.painter.exceeds_screen_size() { reedline_events.push(ReedlineEvent::Repaint); }; From e2b4408d47513a415f666b4eb33f9376bccd79b6 Mon Sep 17 00:00:00 2001 From: sholderbach Date: Tue, 13 Sep 2022 22:13:17 +0200 Subject: [PATCH 3/3] Fix accidental always repaint --- src/engine.rs | 2 -- src/painting/painter.rs | 7 ------- 2 files changed, 9 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index b97bab33..4d8e1412 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -504,8 +504,6 @@ impl Reedline { if let Some(ec) = last_edit_commands { reedline_events.push(ReedlineEvent::Edit(ec)); } - } else if !self.painter.exceeds_screen_size() { - reedline_events.push(ReedlineEvent::Repaint); }; for event in reedline_events.drain(..) { diff --git a/src/painting/painter.rs b/src/painting/painter.rs index a3d52138..97df0a88 100644 --- a/src/painting/painter.rs +++ b/src/painting/painter.rs @@ -81,13 +81,6 @@ impl Painter { self.screen_height() - self.prompt_start_row } - /// Check if the currently painted content exceeds the size of the screen - /// and thus should not be repainted without reason (disable animation - /// repaint) - pub(crate) fn exceeds_screen_size(&self) -> bool { - self.large_buffer - } - /// Sets the prompt origin position and screen size for a new line editor /// invocation ///