mirror of https://github.com/helix-editor/helix
Run shell commands asynchronously (#6373)
parent
9eb11214b1
commit
28632c6cee
|
@ -2060,18 +2060,14 @@ fn run_shell_command(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let shell = &cx.editor.config().shell;
|
let shell = cx.editor.config().shell.clone();
|
||||||
let (output, success) = shell_impl(shell, &args.join(" "), None)?;
|
let args = args.join(" ");
|
||||||
if success {
|
|
||||||
cx.editor.set_status("Command succeeded");
|
|
||||||
} else {
|
|
||||||
cx.editor.set_error("Command failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if !output.is_empty() {
|
let callback = async move {
|
||||||
let callback = async move {
|
let (output, success) = shell_impl_async(&shell, &args, None).await?;
|
||||||
let call: job::Callback = Callback::EditorCompositor(Box::new(
|
let call: job::Callback = Callback::EditorCompositor(Box::new(
|
||||||
move |editor: &mut Editor, compositor: &mut Compositor| {
|
move |editor: &mut Editor, compositor: &mut Compositor| {
|
||||||
|
if !output.is_empty() {
|
||||||
let contents = ui::Markdown::new(
|
let contents = ui::Markdown::new(
|
||||||
format!("```sh\n{}\n```", output),
|
format!("```sh\n{}\n```", output),
|
||||||
editor.syn_loader.clone(),
|
editor.syn_loader.clone(),
|
||||||
|
@ -2080,13 +2076,17 @@ fn run_shell_command(
|
||||||
helix_core::Position::new(editor.cursor().0.unwrap_or_default().row, 2),
|
helix_core::Position::new(editor.cursor().0.unwrap_or_default().row, 2),
|
||||||
));
|
));
|
||||||
compositor.replace_or_push("shell", popup);
|
compositor.replace_or_push("shell", popup);
|
||||||
},
|
}
|
||||||
));
|
if success {
|
||||||
Ok(call)
|
editor.set_status("Command succeeded");
|
||||||
};
|
} else {
|
||||||
|
editor.set_error("Command failed");
|
||||||
cx.jobs.callback(callback);
|
}
|
||||||
}
|
},
|
||||||
|
));
|
||||||
|
Ok(call)
|
||||||
|
};
|
||||||
|
cx.jobs.callback(callback);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue