From 2a7b368441fbb3b742845dbd84f9c77162556d14 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 10 Jun 2024 09:37:47 -0400 Subject: [PATCH] Make backend persistence opt-in --- cursive-core/src/backend.rs | 8 ++++++++ cursive/src/backends/crossterm.rs | 4 ++++ cursive/src/backends/curses/n.rs | 4 ++++ cursive/src/backends/curses/pan.rs | 4 ++++ cursive/src/backends/termion.rs | 4 ++++ 5 files changed, 24 insertions(+) diff --git a/cursive-core/src/backend.rs b/cursive-core/src/backend.rs index 99e67e80..c0bcd849 100644 --- a/cursive-core/src/backend.rs +++ b/cursive-core/src/backend.rs @@ -81,6 +81,14 @@ pub trait Backend { /// Any call to `print_at` from now on should use the given effect. fn set_effect(&self, effect: theme::Effect); + /// Returns `true` if the backend has persistent output. + /// + /// If true, this means that output stays there between calls to + /// `refresh()`, so only delta needs to be sent. + fn is_persistent(&self) -> bool { + false + } + /// Disables the given effect. fn unset_effect(&self, effect: theme::Effect); diff --git a/cursive/src/backends/crossterm.rs b/cursive/src/backends/crossterm.rs index 5e0234e8..51ecc7ef 100644 --- a/cursive/src/backends/crossterm.rs +++ b/cursive/src/backends/crossterm.rs @@ -327,6 +327,10 @@ impl Drop for Backend { } impl backend::Backend for Backend { + fn is_persistent(&self) -> bool { + true + } + fn poll_event(&mut self) -> Option { match poll(Duration::from_millis(1)) { Ok(true) => match read() { diff --git a/cursive/src/backends/curses/n.rs b/cursive/src/backends/curses/n.rs index 14497d4b..17750b79 100644 --- a/cursive/src/backends/curses/n.rs +++ b/cursive/src/backends/curses/n.rs @@ -322,6 +322,10 @@ impl backend::Backend for Backend { "ncurses" } + fn is_persistent(&self) -> bool { + true + } + fn set_title(&mut self, title: String) { write_to_tty(format!("\x1B]0;{title}\x07").as_bytes()).unwrap(); } diff --git a/cursive/src/backends/curses/pan.rs b/cursive/src/backends/curses/pan.rs index 1fd3fb26..cedaa9ad 100644 --- a/cursive/src/backends/curses/pan.rs +++ b/cursive/src/backends/curses/pan.rs @@ -377,6 +377,10 @@ impl backend::Backend for Backend { "pancurses" } + fn is_persistent(&self) -> bool { + true + } + fn set_title(&mut self, title: String) { print!("\x1B]0;{title}\x07"); stdout().flush().expect("could not flush stdout"); diff --git a/cursive/src/backends/termion.rs b/cursive/src/backends/termion.rs index 3d613a6c..b2d80e4d 100644 --- a/cursive/src/backends/termion.rs +++ b/cursive/src/backends/termion.rs @@ -267,6 +267,10 @@ impl backend::Backend for Backend { "termion" } + fn is_persistent(&self) -> bool { + true + } + fn set_title(&mut self, title: String) { write!(self.terminal.get_mut(), "\x1B]0;{title}\x07").unwrap(); }