Skip to content

Commit

Permalink
add redraw command (helix-editor#4354)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
jrvidal and the-mikedavis authored Dec 15, 2022
1 parent 42ad1a9 commit f916915
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/typable-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@
| `:pipe` | Pipe each selection to the shell command. |
| `:pipe-to` | Pipe each selection to the shell command, ignoring output. |
| `:run-shell-command`, `:sh` | Run a shell command |
| `:redraw` | Clear and re-render the whole UI |
29 changes: 29 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,28 @@ fn run_shell_command(
Ok(())
}

fn redraw(
cx: &mut compositor::Context,
_args: &[Cow<str>],
event: PromptEvent,
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}

let callback = Box::pin(async move {
let call: job::Callback = Box::new(|_editor, compositor| {
compositor.clear().expect("unable to redraw");
});

Ok(call)
});

cx.jobs.callback(callback);

Ok(())
}

pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand {
name: "quit",
Expand Down Expand Up @@ -2323,6 +2345,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
fun: run_shell_command,
completer: Some(completers::directory),
},
TypableCommand {
name: "redraw",
aliases: &[],
doc: "Clear and re-render the whole UI",
fun: redraw,
completer: None,
},
];

pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
Expand Down
4 changes: 4 additions & 0 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ impl Compositor {
.find(|component| component.id() == Some(id))
.and_then(|component| component.as_any_mut().downcast_mut())
}

pub fn clear(&mut self) -> std::io::Result<()> {
self.terminal.clear()
}
}

// View casting, taken straight from Cursive
Expand Down

0 comments on commit f916915

Please sign in to comment.