From bcee1f4c028012a24ef7ebbda1f80c0decb2375e Mon Sep 17 00:00:00 2001 From: LoricAndre <57358788+LoricAndre@users.noreply.github.com> Date: Wed, 27 Nov 2024 20:01:11 +0100 Subject: [PATCH] =?UTF-8?q?feat!:=20do=20not=20check=20for=20expect=20befo?= =?UTF-8?q?re=20printing=20the=20argument=20of=20accept=E2=80=A6=20(#625)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat!: do not check for expect before printing the argument of accept(...) * fix tests --------- Co-authored-by: LoricAndre --- skim/src/bin/main.rs | 12 ++---------- skim/src/options.rs | 2 +- test/run.sh | 1 + test/test_skim.py | 11 +++++++++++ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/skim/src/bin/main.rs b/skim/src/bin/main.rs index 3e715aec..c89cf7c2 100644 --- a/skim/src/bin/main.rs +++ b/skim/src/bin/main.rs @@ -129,16 +129,8 @@ fn sk_main() -> Result { print!("{}{}", result.cmd, bin_options.output_ending); } - if !opts.expect.is_empty() { - match result.final_event { - Event::EvActAccept(Some(accept_key)) => { - print!("{}{}", accept_key, bin_options.output_ending); - } - Event::EvActAccept(None) => { - print!("{}", bin_options.output_ending); - } - _ => {} - } + if let Event::EvActAccept(Some(accept_key)) = result.final_event { + print!("{}{}", accept_key, bin_options.output_ending); } for item in result.selected_items.iter() { diff --git a/skim/src/options.rs b/skim/src/options.rs index c5128fef..881abeea 100644 --- a/skim/src/options.rs +++ b/skim/src/options.rs @@ -222,7 +222,7 @@ pub struct SkimOptions { /// /// ACTION: DEFAULT BINDINGS (NOTES): /// abort ctrl-c ctrl-q esc - /// accept enter + /// accept(...) enter (the argument will be printed when the binding is triggered) /// append-and-select /// backward-char ctrl-b left /// backward-delete-char ctrl-h bspace diff --git a/test/run.sh b/test/run.sh index bb5bdb56..eb1e173a 100755 --- a/test/run.sh +++ b/test/run.sh @@ -4,6 +4,7 @@ set -euo pipefail TEST_CLASS=test_skim.TestSkim +cd $(dirname "$0") tests=$(sed -n 's/^\s\+def \(test_\w\+\)(self.*):\s*$/\1/p' test_skim.py | \ sk --multi) diff --git a/test/test_skim.py b/test/test_skim.py index 034dff3e..dcf56e04 100644 --- a/test/test_skim.py +++ b/test/test_skim.py @@ -1375,6 +1375,17 @@ class TestSkim(TestBase): self.tmux.until(lambda l: l.ready_with_matches(2)) self.tmux.until(lambda l: l[-3] == '> a b') + def test_624_accept_no_expect(self): + input_cmd = "echo -e 'a b c\\nd e f'" + args = '--bind ctrl-a:accept:hello' + self.tmux.send_keys(f"{input_cmd} | {self.sk(args)}", Key('Enter')) + self.tmux.until(lambda l: l.ready_with_matches(2)) + self.tmux.send_keys(Ctrl('a')) + out = self.readonce().split('\n') + self.assertEqual(out[-1], '') + self.assertEqual(out[-2], 'a b c') + self.assertEqual(out[-3], 'hello') + def find_prompt(lines, interactive=False, reverse=False): linen = -1 prompt = ">"