1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package tui
type KeyMap []KeyBinding
type KeyBinding struct {
Pattern KeyPattern
Handler func(KeyEvent)
Stop bool
Preempt bool
}
type KeyPattern struct {
Key Key
Rune rune
AnyRune bool
AnyKey bool
Mod Modifier
ExcludeMods Modifier
FocusRequired bool
}
func On(m KeyMatcher, handler func(KeyEvent)) KeyBinding {
return KeyBinding{Pattern: m.keyPattern(), Handler: handler}
}
func OnStop(m KeyMatcher, handler func(KeyEvent)) KeyBinding {
return KeyBinding{Pattern: m.keyPattern(), Handler: handler, Stop: true}
}
func OnPreemptStop(m KeyMatcher, handler func(KeyEvent)) KeyBinding {
return KeyBinding{Pattern: m.keyPattern(), Handler: handler, Stop: true, Preempt: true}
}
func OnFocused(m KeyMatcher, handler func(KeyEvent)) KeyBinding {
p := m.keyPattern()
p.FocusRequired = true
return KeyBinding{Pattern: p, Handler: handler, Stop: true}
}
|