Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add redraw command #6949

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/generated/typable-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@
| `:run-shell-command`, `:sh` | Run a shell command |
| `:reset-diff-change`, `:diffget`, `:diffg` | Reset the diff change at the cursor position. |
| `:clear-register` | Clear given register. If no argument is provided, clear all registers. |
| `:redraw` | Clear and re-render the whole UI |
5 changes: 5 additions & 0 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ impl Application {
}

async fn render(&mut self) {
if self.compositor.full_redraw {
pascalkuthe marked this conversation as resolved.
Show resolved Hide resolved
self.terminal.clear().expect("Cannot clear the terminal");
self.compositor.full_redraw = false;
}

let mut cx = crate::compositor::Context {
editor: &mut self.editor,
jobs: &mut self.jobs,
Expand Down
30 changes: 30 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,29 @@ fn clear_register(
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 =
job::Callback::EditorCompositor(Box::new(|_editor, compositor| {
compositor.need_full_redraw();
}));

Ok(call)
});

cx.jobs.callback(callback);

Ok(())
}

pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand {
name: "quit",
Expand Down Expand Up @@ -2877,6 +2900,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
fun: clear_register,
signature: CommandSignature::none(),
},
TypableCommand {
name: "redraw",
aliases: &[],
doc: "Clear and re-render the whole UI",
fun: redraw,
signature: CommandSignature::none(),
},
];

pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
Expand Down
6 changes: 6 additions & 0 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub struct Compositor {
area: Rect,

pub(crate) last_picker: Option<Box<dyn Component>>,
pub(crate) full_redraw: bool,
pascalkuthe marked this conversation as resolved.
Show resolved Hide resolved
}

impl Compositor {
Expand All @@ -88,6 +89,7 @@ impl Compositor {
layers: Vec::new(),
area,
last_picker: None,
full_redraw: false,
}
}

Expand Down Expand Up @@ -206,6 +208,10 @@ impl Compositor {
.find(|component| component.id() == Some(id))
.and_then(|component| component.as_any_mut().downcast_mut())
}

pub fn need_full_redraw(&mut self) {
self.full_redraw = true;
}
}

// View casting, taken straight from Cursive
Expand Down
Loading