fix(commands): change pipe
-like output trimming (#11183)
This commit is contained in:
parent
850c9f691e
commit
535351067c
1 changed files with 13 additions and 7 deletions
|
@ -5745,14 +5745,20 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
|
||||||
let output = if let Some(output) = shell_output.as_ref() {
|
let output = if let Some(output) = shell_output.as_ref() {
|
||||||
output.clone()
|
output.clone()
|
||||||
} else {
|
} else {
|
||||||
let fragment = range.slice(text);
|
let input = range.slice(text);
|
||||||
match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
|
match shell_impl(shell, cmd, pipe.then(|| input.into())) {
|
||||||
Ok(result) => {
|
Ok(mut output) => {
|
||||||
let result = Tendril::from(result.trim_end());
|
if !input.ends_with("\n") && !output.is_empty() && output.ends_with('\n') {
|
||||||
if !pipe {
|
output.pop();
|
||||||
shell_output = Some(result.clone());
|
if output.ends_with('\r') {
|
||||||
|
output.pop();
|
||||||
}
|
}
|
||||||
result
|
}
|
||||||
|
|
||||||
|
if !pipe {
|
||||||
|
shell_output = Some(output.clone());
|
||||||
|
}
|
||||||
|
output
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
cx.editor.set_error(err.to_string());
|
cx.editor.set_error(err.to_string());
|
||||||
|
|
Loading…
Add table
Reference in a new issue