diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2017-04-28 02:36:36 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2017-04-28 02:36:36 +0900 |
commit | 6b592137b966299a8a1324ccb1ddf3d6aaa7bbc9 (patch) | |
tree | f93216eee9d31f48816e60269125d66dc74f2313 | |
parent | d5e72bf55d0bb317a3b9515885e92d94097b38fe (diff) |
Add support for ctrl-alt-[a-z] key chords
Close #906
-rw-r--r-- | man/man1/fzf.1 | 3 | ||||
-rw-r--r-- | src/options.go | 6 | ||||
-rw-r--r-- | src/options_test.go | 9 | ||||
-rw-r--r-- | src/tui/light.go | 5 | ||||
-rw-r--r-- | src/tui/ncurses.go | 2 | ||||
-rw-r--r-- | src/tui/tcell.go | 61 | ||||
-rw-r--r-- | src/tui/tui.go | 5 |
7 files changed, 52 insertions, 39 deletions
diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 6649f02c..0e718083 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .. -.TH fzf 1 "Mar 2017" "fzf 0.16.6" "fzf - a command-line fuzzy finder" +.TH fzf 1 "Apr 2017" "fzf 0.16.7" "fzf - a command-line fuzzy finder" .SH NAME fzf - a command-line fuzzy finder @@ -439,6 +439,7 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR .B AVAILABLE KEYS: (SYNONYMS) \fIctrl-[a-z]\fR \fIctrl-space\fR + \fIctrl-alt-[a-z]\fR \fIalt-[a-z]\fR \fIalt-[0-9]\fR \fIf[1-12]\fR diff --git a/src/options.go b/src/options.go index 0c84a3a9..8dd58f08 100644 --- a/src/options.go +++ b/src/options.go @@ -401,7 +401,7 @@ func parseKeyChords(str string, message string) map[int]string { case "ctrl-space": chord = tui.CtrlSpace case "alt-enter", "alt-return": - chord = tui.AltEnter + chord = tui.CtrlAltM case "alt-space": chord = tui.AltSpace case "alt-/": @@ -437,7 +437,9 @@ func parseKeyChords(str string, message string) map[int]string { case "f12": chord = tui.F12 default: - if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) { + if len(key) == 10 && strings.HasPrefix(lkey, "ctrl-alt-") && isAlphabet(lkey[9]) { + chord = tui.CtrlAltA + int(lkey[9]) - 'a' + } else if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) { chord = tui.CtrlA + int(lkey[5]) - 'a' } else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) { chord = tui.AltA + int(lkey[4]) - 'a' diff --git a/src/options_test.go b/src/options_test.go index 29d98421..907faf03 100644 --- a/src/options_test.go +++ b/src/options_test.go @@ -125,14 +125,14 @@ func TestIrrelevantNth(t *testing.T) { } func TestParseKeys(t *testing.T) { - pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ALT-enter,alt-SPACE", "") + pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ctrl-alt-a,ALT-enter,alt-SPACE", "") check := func(i int, s string) { if pairs[i] != s { t.Errorf("%s != %s", pairs[i], s) } } - if len(pairs) != 11 { - t.Error(11) + if len(pairs) != 12 { + t.Error(12) } check(tui.CtrlZ, "ctrl-z") check(tui.AltZ, "alt-z") @@ -143,7 +143,8 @@ func TestParseKeys(t *testing.T) { check(tui.CtrlA+'g'-'a', "ctrl-G") check(tui.AltZ+'J', "J") check(tui.AltZ+'g', "g") - check(tui.AltEnter, "ALT-enter") + check(tui.CtrlAltA, "ctrl-alt-a") + check(tui.CtrlAltM, "ALT-enter") check(tui.AltSpace, "alt-SPACE") // Synonyms diff --git a/src/tui/light.go b/src/tui/light.go index 3f6985f5..7819050c 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -344,9 +344,10 @@ func (r *LightRenderer) escSequence(sz *int) Event { return Event{ESC, 0, nil} } *sz = 2 + if r.buffer[1] >= 1 && r.buffer[1] <= 'z'-'a'+1 { + return Event{int(CtrlAltA + r.buffer[1] - 1), 0, nil} + } switch r.buffer[1] { - case 13: - return Event{AltEnter, 0, nil} case 32: return Event{AltSpace, 0, nil} case 47: diff --git a/src/tui/ncurses.go b/src/tui/ncurses.go index 4b88b447..ba3a1cfb 100644 --- a/src/tui/ncurses.go +++ b/src/tui/ncurses.go @@ -353,7 +353,7 @@ func escSequence() Event { case C.ERR: return Event{ESC, 0, nil} case CtrlM: - return Event{AltEnter, 0, nil} + return Event{CtrlAltM, 0, nil} case '/': return Event{AltSlash, 0, nil} case ' ': diff --git a/src/tui/tcell.go b/src/tui/tcell.go index 964c19e1..bda5d082 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -221,58 +221,65 @@ func (r *FullscreenRenderer) GetChar() Event { // process keyboard: case *tcell.EventKey: alt := (ev.Modifiers() & tcell.ModAlt) > 0 + keyfn := func(r rune) int { + if alt { + return CtrlAltA - 'a' + int(r) + } + return CtrlA - 'a' + int(r) + } switch ev.Key() { case tcell.KeyCtrlA: - return Event{CtrlA, 0, nil} + return Event{keyfn('a'), 0, nil} case tcell.KeyCtrlB: - return Event{CtrlB, 0, nil} + return Event{keyfn('b'), 0, nil} case tcell.KeyCtrlC: - return Event{CtrlC, 0, nil} + return Event{keyfn('c'), 0, nil} case tcell.KeyCtrlD: - return Event{CtrlD, 0, nil} + return Event{keyfn('d'), 0, nil} case tcell.KeyCtrlE: - return Event{CtrlE, 0, nil} + return Event{keyfn('e'), 0, nil} case tcell.KeyCtrlF: - return Event{CtrlF, 0, nil} + return Event{keyfn('f'), 0, nil} case tcell.KeyCtrlG: - return Event{CtrlG, 0, nil} + return Event{keyfn('g'), 0, nil} + case tcell.KeyCtrlH: + return Event{keyfn('h'), 0, nil} + case tcell.KeyCtrlI: + return Event{keyfn('i'), 0, nil} case tcell.KeyCtrlJ: - return Event{CtrlJ, 0, nil} + return Event{keyfn('j'), 0, nil} case tcell.KeyCtrlK: - return Event{CtrlK, 0, nil} + return Event{keyfn('k'), 0, nil} case tcell.KeyCtrlL: - return Event{CtrlL, 0, nil} + return Event{keyfn('l'), 0, nil} case tcell.KeyCtrlM: - if alt { - return Event{AltEnter, 0, nil} - } - return Event{CtrlM, 0, nil} + return Event{keyfn('m'), 0, nil} case tcell.KeyCtrlN: - return Event{CtrlN, 0, nil} + return Event{keyfn('n'), 0, nil} case tcell.KeyCtrlO: - return Event{CtrlO, 0, nil} + return Event{keyfn('o'), 0, nil} case tcell.KeyCtrlP: - return Event{CtrlP, 0, nil} + return Event{keyfn('p'), 0, nil} case tcell.KeyCtrlQ: - return Event{CtrlQ, 0, nil} + return Event{keyfn('q'), 0, nil} case tcell.KeyCtrlR: - return Event{CtrlR, 0, nil} + return Event{keyfn('r'), 0, nil} case tcell.KeyCtrlS: - return Event{CtrlS, 0, nil} + return Event{keyfn('s'), 0, nil} case tcell.KeyCtrlT: - return Event{CtrlT, 0, nil} + return Event{keyfn('t'), 0, nil} case tcell.KeyCtrlU: - return Event{CtrlU, 0, nil} + return Event{keyfn('u'), 0, nil} case tcell.KeyCtrlV: - return Event{CtrlV, 0, nil} + return Event{keyfn('v'), 0, nil} case tcell.KeyCtrlW: - return Event{CtrlW, 0, nil} + return Event{keyfn('w'), 0, nil} case tcell.KeyCtrlX: - return Event{CtrlX, 0, nil} + return Event{keyfn('x'), 0, nil} case tcell.KeyCtrlY: - return Event{CtrlY, 0, nil} + return Event{keyfn('y'), 0, nil} case tcell.KeyCtrlZ: - return Event{CtrlZ, 0, nil} + return Event{keyfn('z'), 0, nil} case tcell.KeyCtrlSpace: return Event{CtrlSpace, 0, nil} case tcell.KeyBackspace, tcell.KeyBackspace2: diff --git a/src/tui/tui.go b/src/tui/tui.go index f8d905ab..d360c4ec 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -75,7 +75,6 @@ const ( F11 F12 - AltEnter AltSpace AltSlash AltBS @@ -90,7 +89,9 @@ const ( // Reset iota AltD AltE AltF - AltZ = AltA + 'z' - 'a' + AltZ = AltA + 'z' - 'a' + CtrlAltA = AltZ + 1 + CtrlAltM = CtrlAltA + 'm' - 'a' ) const ( |