Skip to content

Commit

Permalink
feat!: do not check for expect before printing the argument of accept… (
Browse files Browse the repository at this point in the history
#625)

* feat!: do not check for expect before printing the argument of accept(...)

* fix tests

---------

Co-authored-by: LoricAndre <[email protected]>
  • Loading branch information
LoricAndre and LoricAndre authored Nov 27, 2024
1 parent 4144879 commit bcee1f4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
12 changes: 2 additions & 10 deletions skim/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,8 @@ fn sk_main() -> Result<i32, SkMainError> {
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() {
Expand Down
2 changes: 1 addition & 1 deletion skim/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions test/test_skim.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,17 @@ def test_622_combined_multiple_flags_with_nth(self):
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 = ">"
Expand Down

0 comments on commit bcee1f4

Please sign in to comment.