Allow alt-enter and alt-space for --bind (#571)

This commit is contained in:
Junegunn Choi 2016-05-13 00:36:13 +09:00
parent 66f86e1870
commit dd4be1da38
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 15 additions and 3 deletions

View File

@ -81,6 +81,8 @@ const (
F3 F3
F4 F4
AltEnter
AltSpace
AltBS AltBS
AltA AltA
AltB AltB
@ -417,6 +419,10 @@ func escSequence(sz *int) Event {
} }
*sz = 2 *sz = 2
switch _buf[1] { switch _buf[1] {
case 13:
return Event{AltEnter, 0, nil}
case 32:
return Event{AltSpace, 0, nil}
case 98: case 98:
return Event{AltB, 0, nil} return Event{AltB, 0, nil}
case 100: case 100:

View File

@ -315,6 +315,10 @@ func parseKeyChords(str string, message string) map[int]string {
chord = curses.AltZ + int(' ') chord = curses.AltZ + int(' ')
case "bspace", "bs": case "bspace", "bs":
chord = curses.BSpace chord = curses.BSpace
case "alt-enter", "alt-return":
chord = curses.AltEnter
case "alt-space":
chord = curses.AltSpace
case "alt-bs", "alt-bspace": case "alt-bs", "alt-bspace":
chord = curses.AltBS chord = curses.AltBS
case "tab": case "tab":

View File

@ -123,14 +123,14 @@ func TestIrrelevantNth(t *testing.T) {
} }
func TestParseKeys(t *testing.T) { func TestParseKeys(t *testing.T) {
pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g", "") pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ALT-enter,alt-SPACE", "")
check := func(i int, s string) { check := func(i int, s string) {
if pairs[i] != s { if pairs[i] != s {
t.Errorf("%s != %s", pairs[i], s) t.Errorf("%s != %s", pairs[i], s)
} }
} }
if len(pairs) != 9 { if len(pairs) != 11 {
t.Error(9) t.Error(11)
} }
check(curses.CtrlZ, "ctrl-z") check(curses.CtrlZ, "ctrl-z")
check(curses.AltZ, "alt-z") check(curses.AltZ, "alt-z")
@ -141,6 +141,8 @@ func TestParseKeys(t *testing.T) {
check(curses.CtrlA+'g'-'a', "ctrl-G") check(curses.CtrlA+'g'-'a', "ctrl-G")
check(curses.AltZ+'J', "J") check(curses.AltZ+'J', "J")
check(curses.AltZ+'g', "g") check(curses.AltZ+'g', "g")
check(curses.AltEnter, "ALT-enter")
check(curses.AltSpace, "alt-SPACE")
// Synonyms // Synonyms
pairs = parseKeyChords("enter,Return,space,tab,btab,esc,up,down,left,right", "") pairs = parseKeyChords("enter,Return,space,tab,btab,esc,up,down,left,right", "")