Skip to content

Commit

Permalink
Run shell commands asynchronously (helix-editor#6373)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah authored and Schuyler Mortimer committed Jul 10, 2024
1 parent 68b7e8d commit fb822ad
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2061,18 +2061,14 @@ fn run_shell_command(
return Ok(());
}

let shell = &cx.editor.config().shell;
let (output, success) = shell_impl(shell, &args.join(" "), None)?;
if success {
cx.editor.set_status("Command succeeded");
} else {
cx.editor.set_error("Command failed");
}
let shell = cx.editor.config().shell.clone();
let args = args.join(" ");

if !output.is_empty() {
let callback = async move {
let call: job::Callback = Callback::EditorCompositor(Box::new(
move |editor: &mut Editor, compositor: &mut Compositor| {
let callback = async move {
let (output, success) = shell_impl_async(&shell, &args, None).await?;
let call: job::Callback = Callback::EditorCompositor(Box::new(
move |editor: &mut Editor, compositor: &mut Compositor| {
if !output.is_empty() {
let contents = ui::Markdown::new(
format!("```sh\n{}\n```", output),
editor.syn_loader.clone(),
Expand All @@ -2081,13 +2077,17 @@ fn run_shell_command(
helix_core::Position::new(editor.cursor().0.unwrap_or_default().row, 2),
));
compositor.replace_or_push("shell", popup);
},
));
Ok(call)
};

cx.jobs.callback(callback);
}
}
if success {
editor.set_status("Command succeeded");
} else {
editor.set_error("Command failed");
}
},
));
Ok(call)
};
cx.jobs.callback(callback);

Ok(())
}
Expand Down

0 comments on commit fb822ad

Please sign in to comment.