From cc0d5539ba35b480ae3fb590c562a08637b37064 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 22 Jul 2015 22:56:53 +0900 Subject: [PATCH] Add "eof" action which closes the finder only when input is empty Close #289 --- CHANGELOG.md | 2 ++ man/man1/fzf.1 | 1 + src/options.go | 2 ++ src/terminal.go | 5 +++++ test/test_go.rb | 13 +++++++++++++ 5 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b6f5e5..e3136ee8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ CHANGELOG - Added options for sticky header - `--header-file` - `--header-lines` +- Added `eof` action which closes the finder only when the input is empty + - e.g. `export FZF_DEFAULT_OPTS="--bind esc:eof"` ### Minor improvements/fixes diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 3dc7177b..33db7d50 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -193,6 +193,7 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR \fBdeselect-all\fR \fBdown\fR \fIctrl-j ctrl-n down\fR \fBend-of-line\fR \fIctrl-e end\fR + \fBeof\fR \fBexecute(...)\fR (see below for the details) \fBforward-char\fR \fIctrl-f right\fR \fBforward-word\fR \fIalt-f shift-right\fR diff --git a/src/options.go b/src/options.go index 17df2210..ad5f6929 100644 --- a/src/options.go +++ b/src/options.go @@ -499,6 +499,8 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b keymap[key] = actDeleteChar case "end-of-line": keymap[key] = actEndOfLine + case "eof": + keymap[key] = actEof case "forward-char": keymap[key] = actForwardChar case "forward-word": diff --git a/src/terminal.go b/src/terminal.go index c5c9e918..6d95d26c 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -103,6 +103,7 @@ const ( actClearScreen actDeleteChar actEndOfLine + actEof actForwardChar actForwardWord actKillLine @@ -813,6 +814,10 @@ func (t *Terminal) Loop() { } case actEndOfLine: t.cx = len(t.input) + case actEof: + if len(t.input) == 0 { + req(reqQuit) + } case actForwardChar: if t.cx < len(t.input) { t.cx++ diff --git a/test/test_go.rb b/test/test_go.rb index 7c5cd80e..4f247edd 100644 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -718,6 +718,19 @@ class TestGoFZF < TestBase end end + def test_eof + tmux.send_keys "seq 100 | #{fzf "--bind 2:eof"}", :Enter + tmux.until { |lines| lines[-2].include?('100/100') } + tmux.send_keys '123' + tmux.until do |lines| + lines[-1] == '> 13' && lines[-2].include?('1/100') + end + tmux.send_keys :BSpace, :BSpace + tmux.until { |lines| lines[-1] == '>' } + tmux.send_keys 2 + tmux.prepare + end + private def writelines path, lines File.unlink path while File.exists? path