on master help sign in
add redraw command (#6949)

Co-authored-by: Roberto Vidal <vidal.roberto.j@gmail.com>

commit8017bb29990bd15eb31542fa25e8cb1207364b07 authorWeiyuan Wu <weiyuan@crows.land> dateFri 8 Sep 2023, 09:46 (3 years ago) parentc0fd8bc
4 files changed+42
book/src/generated/typable-cmd.md+1 helix-term/src/application.rs+5 helix-term/src/commands/typed.rs+30 helix-term/src/compositor.rs+6
book/src/generated/typable-cmd.md+1
@@ -83,3 +83,4 @@
8383| `:run-shell-command`, `:sh` | Run a shell command |
8484| `:reset-diff-change`, `:diffget`, `:diffg` | Reset the diff change at the cursor position. |
8585| `: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 {
251251 }
252252
253253 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+
254259 let mut cx = crate::compositor::Context {
255260 editor: &mut self.editor,
256261 jobs: &mut self.jobs,
helix-term/src/commands/typed.rs+30
@@ -2291,6 +2291,29 @@ fn clear_register(
22912291 Ok(())
22922292}
22932293
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+
22942317pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
22952318 TypableCommand {
22962319 name: "quit",
@@ -2877,6 +2900,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
28772900 fun: clear_register,
28782901 signature: CommandSignature::none(),
28792902 },
2903+ TypableCommand {
2904+ name: "redraw",
2905+ aliases: &[],
2906+ doc: "Clear and re-render the whole UI",
2907+ fun: redraw,
2908+ signature: CommandSignature::none(),
2909+ },
28802910];
28812911
28822912pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
helix-term/src/compositor.rs+6
@@ -80,6 +80,7 @@ pub struct Compositor {
8080 area: Rect,
8181
8282 pub(crate) last_picker: Option<Box<dyn Component>>,
83+ pub(crate) full_redraw: bool,
8384}
8485
8586impl Compositor {
@@ -88,6 +89,7 @@ impl Compositor {
8889 layers: Vec::new(),
8990 area,
9091 last_picker: None,
92+ full_redraw: false,
9193 }
9294 }
9395
@@ -206,6 +208,10 @@ impl Compositor {
206208 .find(|component| component.id() == Some(id))
207209 .and_then(|component| component.as_any_mut().downcast_mut())
208210 }
211+
212+ pub fn need_full_redraw(&mut self) {
213+ self.full_redraw = true;
214+ }
209215}
210216
211217// View casting, taken straight from Cursive