on master help sign in
add redraw command (#4354)
f916915Roberto Vidal
book/src/generated/typable-cmd.md+1
@@ -73,3 +73,4 @@
73| `:pipe` | Pipe each selection to the shell command. |
73| `:pipe` | Pipe each selection to the shell command. |
74| `:pipe-to` | Pipe each selection to the shell command, ignoring output. |
74| `:pipe-to` | Pipe each selection to the shell command, ignoring output. |
75| `:run-shell-command`, `:sh` | Run a shell command |
75| `: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(
1808 Ok(())
1808 Ok(())
1809}
1809}
1810
1810
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+
1811pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1833pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1812 TypableCommand {
1834 TypableCommand {
1813 name: "quit",
1835 name: "quit",
@@ -2323,6 +2345,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2323 fun: run_shell_command,
2345 fun: run_shell_command,
2324 completer: Some(completers::directory),
2346 completer: Some(completers::directory),
2325 },
2347 },
2348+ TypableCommand {
2349+ name: "redraw",
2350+ aliases: &[],
2351+ doc: "Clear and re-render the whole UI",
2352+ fun: redraw,
2353+ completer: None,
2354+ },
2326 ];
2355 ];
2327
2356
2328pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
2357pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
helix-term/src/compositor.rs+4
@@ -197,6 +197,10 @@ impl Compositor {
197 .find(|component| component.id() == Some(id))
197 .find(|component| component.id() == Some(id))
198 .and_then(|component| component.as_any_mut().downcast_mut())
198 .and_then(|component| component.as_any_mut().downcast_mut())
199 }
199 }
200+
201+ pub fn clear(&mut self) -> std::io::Result<()> {
202+ self.terminal.clear()
203+ }
200}
204}
201
205
202// View casting, taken straight from Cursive
206// View casting, taken straight from Cursive