Skip to content

Commit

Permalink
Make backend persistence opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Jun 10, 2024
1 parent 332a6a4 commit 2a7b368
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cursive-core/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions cursive/src/backends/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> {
match poll(Duration::from_millis(1)) {
Ok(true) => match read() {
Expand Down
4 changes: 4 additions & 0 deletions cursive/src/backends/curses/n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions cursive/src/backends/curses/pan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions cursive/src/backends/termion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 2a7b368

Please sign in to comment.