Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Revert "remove anims and resize repaint (#451)"
This reverts commit 59f7144.
  • Loading branch information
sholderbach committed Sep 12, 2022
commit fbcc1c341a5ae5765241573e2add0039d9905c43
18 changes: 16 additions & 2 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ pub struct Reedline {
hinter: Option<Box<dyn Hinter>>,
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,

Expand Down Expand Up @@ -168,6 +171,7 @@ impl Reedline {
hinter,
hide_hints: false,
validator,
animate: false,
use_ansi_coloring: true,
menus: Vec::new(),
buffer_editor: None,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(..) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/painting/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down