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

* add redraw command * update docs * Update helix-term/src/commands/typed.rs Co-authored-by: Michael Davis <mcarsondavis@gmail.com> * update docs Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

commitf916915b53fa6fedd3f9106bcf58163083cc052e authorRoberto Vidal <vidal.roberto.j@gmail.com> dateThu 15 Dec 2022, 09:59 (4 years ago) parent42ad1a9
3 files changed+34
book/src/generated/typable-cmd.md+1 helix-term/src/commands/typed.rs+29 helix-term/src/compositor.rs+4
book/src/generated/typable-cmd.md+1
@@ -73,3 +73,4 @@
7373| `:pipe` | Pipe each selection to the shell command. |
7474| `:pipe-to` | Pipe each selection to the shell command, ignoring output. |
7575| `:run-shell-command`, `:sh` | Run a shell command |
76+| `:redraw` | Clear and re-render the whole UI |
helix-term/src/commands/typed.rs+29
@@ -1808,6 +1808,28 @@ fn run_shell_command(
18081808 Ok(())
18091809}
18101810
1811+fn redraw(
1812+ cx: &mut compositor::Context,
1813+ _args: &[Cow<str>],
1814+ event: PromptEvent,
1815+) -> anyhow::Result<()> {
1816+ if event != PromptEvent::Validate {
1817+ return Ok(());
1818+ }
1819+
1820+ let callback = Box::pin(async move {
1821+ let call: job::Callback = Box::new(|_editor, compositor| {
1822+ compositor.clear().expect("unable to redraw");
1823+ });
1824+
1825+ Ok(call)
1826+ });
1827+
1828+ cx.jobs.callback(callback);
1829+
1830+ Ok(())
1831+}
1832+
18111833pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
18121834 TypableCommand {
18131835 name: "quit",
@@ -2323,6 +2345,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
23232345 fun: run_shell_command,
23242346 completer: Some(completers::directory),
23252347 },
2348+ TypableCommand {
2349+ name: "redraw",
2350+ aliases: &[],
2351+ doc: "Clear and re-render the whole UI",
2352+ fun: redraw,
2353+ completer: None,
2354+ },
23262355 ];
23272356
23282357pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
helix-term/src/compositor.rs+4
@@ -197,6 +197,10 @@ impl Compositor {
197197 .find(|component| component.id() == Some(id))
198198 .and_then(|component| component.as_any_mut().downcast_mut())
199199 }
200+
201+ pub fn clear(&mut self) -> std::io::Result<()> {
202+ self.terminal.clear()
203+ }
200204}
201205
202206// View casting, taken straight from Cursive