Skip to content

Commit

Permalink
refactor(commands): trim end of pipe-like output
Browse files Browse the repository at this point in the history
  • Loading branch information
RoloEdits committed Jun 14, 2024
1 parent 9c479e6 commit 332c3e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
4 changes: 2 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5755,15 +5755,15 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
let mut offset = 0isize;
for range in selection.ranges() {
let output = if let Some(output) = shell_output.as_ref() {
output.clone()
Tendril::from(output.trim_end())
} else {
let fragment = range.slice(text);
match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
Ok(result) => {
if !pipe {
shell_output = Some(result.clone());
}
result
Tendril::from(result.trim_end())
}
Err(err) => {
cx.editor.set_error(err.to_string());
Expand Down
29 changes: 10 additions & 19 deletions helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,10 @@ async fn test_multi_selection_shell_commands() -> anyhow::Result<()> {
"},
"|echo foo<ret>",
indoc! {"\
#[|foo\n]#
#(|foo\n)#
#(|foo\n)#
"},
#[|foo]#
#(|foo)#
#(|foo)#"
},
))
.await?;

Expand All @@ -228,12 +225,9 @@ async fn test_multi_selection_shell_commands() -> anyhow::Result<()> {
"},
"!echo foo<ret>",
indoc! {"\
#[|foo\n]#
lorem
#(|foo\n)#
ipsum
#(|foo\n)#
dolor
#[|foo]#lorem
#(|foo)#ipsum
#(|foo)#dolor
"},
))
.await?;
Expand All @@ -247,12 +241,9 @@ async fn test_multi_selection_shell_commands() -> anyhow::Result<()> {
"},
"<A-!>echo foo<ret>",
indoc! {"\
lorem#[|foo\n]#
ipsum#(|foo\n)#
dolor#(|foo\n)#
lorem#[|foo]#
ipsum#(|foo)#
dolor#(|foo)#
"},
))
.await?;
Expand Down

0 comments on commit 332c3e5

Please sign in to comment.