From c0919dc1285825e1ae512297e21eb548d2ac253c Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 5 Jul 2025 21:26:20 +0200 Subject: [PATCH] Add API to clear the terminal completely instead of incrementally New API uses `buffer.write().clear()` over `printer.clear()` (which is `self.buffer.write().fill(" ")`) helps with properly clear the cursive screen area after invoking side TUI apps within it (i.e. vim) Note, that this is not enough to clear the complete screen in case of using ShadowView. --- cursive-core/src/cursive_root.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cursive-core/src/cursive_root.rs b/cursive-core/src/cursive_root.rs index 77e6b00a..d7f99c2b 100644 --- a/cursive-core/src/cursive_root.rs +++ b/cursive-core/src/cursive_root.rs @@ -39,7 +39,8 @@ pub struct Cursive { menubar: views::Menubar, - pub(crate) needs_clear: bool, + needs_clear: bool, + needs_complete_clear: bool, running: bool, @@ -97,6 +98,7 @@ impl Cursive { menubar: views::Menubar::new(), last_size: Vec2::zero(), needs_clear: true, + needs_complete_clear: false, running: true, cb_source, cb_sink, @@ -128,7 +130,11 @@ impl Cursive { let printer = Printer::new(size, &self.theme, buffer); - if self.needs_clear { + if self.needs_complete_clear { + buffer.write().clear(); + self.needs_complete_clear = false; + self.needs_clear = false; + } else if self.needs_clear { printer.clear(); self.needs_clear = false; } @@ -408,6 +414,14 @@ impl Cursive { self.needs_clear = true; } + /// Force a full redraw on the next frame. + /// + /// [`clear`](Self::clear) clears only working area (that cursive writes to), while this method + /// will do a complete clear. Use it after running external programs, i.e. editor. + pub fn complete_clear(&mut self) { + self.needs_complete_clear = true; + } + /// Loads a theme from the given file. /// /// `filename` must point to a valid toml file.