on master help sign in
add redraw command (#6949)
8017bb2Weiyuan Wu
book/src/generated/typable-cmd.md+1
@@ -83,3 +83,4 @@
83| `:run-shell-command`, `:sh` | Run a shell command |
83| `:run-shell-command`, `:sh` | Run a shell command |
84| `:reset-diff-change`, `:diffget`, `:diffg` | Reset the diff change at the cursor position. |
84| `:reset-diff-change`, `:diffget`, `:diffg` | Reset the diff change at the cursor position. |
85| `:clear-register` | Clear given register. If no argument is provided, clear all registers. |
85| `:clear-register` | Clear given register. If no argument is provided, clear all registers. |
86+| `:redraw` | Clear and re-render the whole UI |
helix-term/src/application.rs+5
@@ -251,6 +251,11 @@ impl Application {
251 }
251 }
252
252
253 async fn render(&mut self) {
253 async fn render(&mut self) {
254+ if self.compositor.full_redraw {
255+ self.terminal.clear().expect("Cannot clear the terminal");
256+ self.compositor.full_redraw = false;
257+ }
258+
254 let mut cx = crate::compositor::Context {
259 let mut cx = crate::compositor::Context {
255 editor: &mut self.editor,
260 editor: &mut self.editor,
256 jobs: &mut self.jobs,
261 jobs: &mut self.jobs,
helix-term/src/commands/typed.rs+30
@@ -2291,6 +2291,29 @@ fn clear_register(
2291 Ok(())
2291 Ok(())
2292}
2292}
2293
2293
2294+fn redraw(
2295+ cx: &mut compositor::Context,
2296+ _args: &[Cow<str>],
2297+ event: PromptEvent,
2298+) -> anyhow::Result<()> {
2299+ if event != PromptEvent::Validate {
2300+ return Ok(());
2301+ }
2302+
2303+ let callback = Box::pin(async move {
2304+ let call: job::Callback =
2305+ job::Callback::EditorCompositor(Box::new(|_editor, compositor| {
2306+ compositor.need_full_redraw();
2307+ }));
2308+
2309+ Ok(call)
2310+ });
2311+
2312+ cx.jobs.callback(callback);
2313+
2314+ Ok(())
2315+}
2316+
2294pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2317pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2295 TypableCommand {
2318 TypableCommand {
2296 name: "quit",
2319 name: "quit",
@@ -2877,6 +2900,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2877 fun: clear_register,
2900 fun: clear_register,
2878 signature: CommandSignature::none(),
2901 signature: CommandSignature::none(),
2879 },
2902 },
2903+ TypableCommand {
2904+ name: "redraw",
2905+ aliases: &[],
2906+ doc: "Clear and re-render the whole UI",
2907+ fun: redraw,
2908+ signature: CommandSignature::none(),
2909+ },
2880];
2910];
2881
2911
2882pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
2912pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
helix-term/src/compositor.rs+6
@@ -80,6 +80,7 @@ pub struct Compositor {
80 area: Rect,
80 area: Rect,
81
81
82 pub(crate) last_picker: Option<Box<dyn Component>>,
82 pub(crate) last_picker: Option<Box<dyn Component>>,
83+ pub(crate) full_redraw: bool,
83}
84}
84
85
85impl Compositor {
86impl Compositor {
@@ -88,6 +89,7 @@ impl Compositor {
88 layers: Vec::new(),
89 layers: Vec::new(),
89 area,
90 area,
90 last_picker: None,
91 last_picker: None,
92+ full_redraw: false,
91 }
93 }
92 }
94 }
93
95
@@ -206,6 +208,10 @@ impl Compositor {
206 .find(|component| component.id() == Some(id))
208 .find(|component| component.id() == Some(id))
207 .and_then(|component| component.as_any_mut().downcast_mut())
209 .and_then(|component| component.as_any_mut().downcast_mut())
208 }
210 }
211+
212+ pub fn need_full_redraw(&mut self) {
213+ self.full_redraw = true;
214+ }
209}
215}
210
216
211// View casting, taken straight from Cursive
217// View casting, taken straight from Cursive