diff --git a/doc.go b/doc.go index dfe9cd2f..66508620 100644 --- a/doc.go +++ b/doc.go @@ -1142,8 +1142,13 @@ On these terminals, keys combined with the alt key are prefixed with 'a' charact map down -Please note that, some key combinations are not possible due to the way terminals work (e.g. control and h combination sends a backspace key instead). -The easiest way to find the name of a key combination is to press the key while lf is running and read the name of the key from the unknown mapping error. +It is possible to combine special keys with modifiers: + + map down + +WARNING: Some key combinations will likely be intercepted by your OS, window manager, or terminal. +Other key combinations cannot be recognized by lf due to the way terminals work (e.g. `Ctrl+h` combination sends a backspace key instead). +The easiest way to find out the name of a key combination and whether it will work on your system is to press the key while lf is running and read the name from the "unknown mapping" error. Mouse buttons are prefixed with 'm' character: diff --git a/docstring.go b/docstring.go index d67e17df..b160b177 100644 --- a/docstring.go +++ b/docstring.go @@ -1224,10 +1224,16 @@ the alt key are prefixed with 'a' character: map down -Please note that, some key combinations are not possible due to the way -terminals work (e.g. control and h combination sends a backspace key instead). -The easiest way to find the name of a key combination is to press the key while -lf is running and read the name of the key from the unknown mapping error. +It is possible to combine special keys with modifiers: + + map down + +WARNING: Some key combinations will likely be intercepted by your OS, +window manager, or terminal. Other key combinations cannot be recognized by lf +due to the way terminals work (e.g. 'Ctrl+h' combination sends a backspace key +instead). The easiest way to find out the name of a key combination and whether +it will work on your system is to press the key while lf is running and read the +name from the "unknown mapping" error. Mouse buttons are prefixed with 'm' character: diff --git a/lf.1 b/lf.1 index 9dfbf0f9..03a43b0f 100644 --- a/lf.1 +++ b/lf.1 @@ -1388,7 +1388,13 @@ Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key when map down .EE .PP -Please note that, some key combinations are not possible due to the way terminals work (e.g. control and h combination sends a backspace key instead). The easiest way to find the name of a key combination is to press the key while lf is running and read the name of the key from the unknown mapping error. +It is possible to combine special keys with modifiers: +.PP +.EX + map down +.EE +.PP +WARNING: Some key combinations will likely be intercepted by your OS, window manager, or terminal. Other key combinations cannot be recognized by lf due to the way terminals work (e.g. `Ctrl+h` combination sends a backspace key instead). The easiest way to find out the name of a key combination and whether it will work on your system is to press the key while lf is running and read the name from the "unknown mapping" error. .PP Mouse buttons are prefixed with 'm' character: .PP diff --git a/misc.go b/misc.go index 451b7601..ea33664b 100644 --- a/misc.go +++ b/misc.go @@ -275,7 +275,7 @@ func naturalLess(s1, s2 string) bool { } } -var reAltKey = regexp.MustCompile(``) +var reModKey = regexp.MustCompile(`<(c|s|a)-(.+)>`) var reWord = regexp.MustCompile(`(\pL|\pN)+`) var reWordBeg = regexp.MustCompile(`([^\pL\pN]|^)(\pL|\pN)`) diff --git a/ui.go b/ui.go index 4534ce16..259071cd 100644 --- a/ui.go +++ b/ui.go @@ -1105,31 +1105,43 @@ func (ui *ui) pollEvent() tcell.Event { case val := <-ui.keyChan: var ch rune var mod tcell.ModMask - k := tcell.KeyRune - if utf8.RuneCountInString(val) == 1 { + if key, ok := gValKey[val]; ok { + return tcell.NewEventKey(key, ch, mod) + } + + switch { + case utf8.RuneCountInString(val) == 1: ch, _ = utf8.DecodeRuneInString(val) - } else { - switch { - case val == "": - ch = '<' - case val == "": - ch = '>' - case val == "": - ch = ' ' - case reAltKey.MatchString(val): - match := reAltKey.FindStringSubmatch(val)[1] - ch, _ = utf8.DecodeRuneInString(match) - mod = tcell.ModMask(tcell.ModAlt) - default: - if key, ok := gValKey[val]; ok { - k = key - } else { - k = tcell.KeyESC - ui.echoerrf("unknown key: %s", val) - } + case val == "": + ch = '<' + case val == "": + ch = '>' + case val == "": + ch = ' ' + case reModKey.MatchString(val): + matches := reModKey.FindStringSubmatch(val) + switch matches[1] { + case "c": + mod = tcell.ModCtrl + case "s": + mod = tcell.ModShift + case "a": + mod = tcell.ModAlt } + val = matches[2] + if utf8.RuneCountInString(val) == 1 { + ch, _ = utf8.DecodeRuneInString(val) + break + } else if key, ok := gValKey["<"+val+">"]; ok { + k = key + break + } + fallthrough + default: + k = tcell.KeyESC + ui.echoerrf("unknown key: %s", val) } return tcell.NewEventKey(k, ch, mod) @@ -1138,6 +1150,21 @@ func (ui *ui) pollEvent() tcell.Event { } } +func addSpecialKeyModifier(val string, mod tcell.ModMask) string { + switch { + case !strings.HasPrefix(val, "<"): + return val + case mod == tcell.ModCtrl && !strings.HasPrefix(val, "" && string(ui.keyAcc) != "" { ui.keyAcc = nil ui.keyCount = nil @@ -1332,6 +1360,7 @@ func readCmdEvent(ev tcell.Event) expr { } } else { val := gKeyVal[tev.Key()] + val = addSpecialKeyModifier(val, tev.Modifiers()) if expr, ok := gOpts.cmdkeys[val]; ok { return expr }