on master help sign in
Run shell commands asynchronously (#6373)
28632c6sarah
helix-term/src/commands/typed.rs+18−18
@@ -2060,18 +2060,14 @@ fn run_shell_command(
2060 return Ok(());
2060 return Ok(());
2061 }
2061 }
2062
2062
2063− let shell = &cx.editor.config().shell;
2063+ let shell = cx.editor.config().shell.clone();
2064− let (output, success) = shell_impl(shell, &args.join(" "), None)?;
2064+ let args = args.join(" ");
2065− if success {
2066− cx.editor.set_status("Command succeeded");
2067− } else {
2068− cx.editor.set_error("Command failed");
2069− }
2070
2065
2071− if !output.is_empty() {
2072− let callback = async move {
2066+ let callback = async move {
2067+ let (output, success) = shell_impl_async(&shell, &args, None).await?;
2073− let call: job::Callback = Callback::EditorCompositor(Box::new(
2068+ let call: job::Callback = Callback::EditorCompositor(Box::new(
2074− move |editor: &mut Editor, compositor: &mut Compositor| {
2069+ move |editor: &mut Editor, compositor: &mut Compositor| {
2070+ if !output.is_empty() {
2075 let contents = ui::Markdown::new(
2071 let contents = ui::Markdown::new(
2076 format!("```sh\n{}\n```", output),
2072 format!("```sh\n{}\n```", output),
2077 editor.syn_loader.clone(),
2073 editor.syn_loader.clone(),
@@ -2080,13 +2076,17 @@ fn run_shell_command(
2080 helix_core::Position::new(editor.cursor().0.unwrap_or_default().row, 2),
2076 helix_core::Position::new(editor.cursor().0.unwrap_or_default().row, 2),
2081 ));
2077 ));
2082 compositor.replace_or_push("shell", popup);
2078 compositor.replace_or_push("shell", popup);
2083− },
2079+ }
2080+ if success {
2081+ editor.set_status("Command succeeded");
2082+ } else {
2083+ editor.set_error("Command failed");
2084+ }
2085+ },
2084− ));
2086+ ));
2085− Ok(call)
2087+ Ok(call)
2086− };
2088+ };
2087−
2088− cx.jobs.callback(callback);
2089+ cx.jobs.callback(callback);
2089− }
2090
2090
2091 Ok(())
2091 Ok(())
2092}
2092}