-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathkeymap.go
56 lines (46 loc) · 1.64 KB
/
keymap.go
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
51
52
53
54
55
56
package uniline
import (
"github.com/tiborvass/uniline/ansi"
)
// Keymap is a hash table mapping Ansi codes to functions.
// There are no locks on this map, if accessing it concurrently
// please consider it as a static map (1 initial write, THEN as many concurrent reads as you wish)
type Keymap map[ansi.Code]func(*Core)
// DefaultKeymap returns a copy of the default Keymap
// Useful if inspection/customization is needed.
func DefaultKeymap() Keymap {
return Keymap{
ansi.NEWLINE: (*Core).Enter,
ansi.CARRIAGE_RETURN: (*Core).Enter,
ansi.CTRL_C: (*Core).Interrupt,
ansi.CTRL_D: (*Core).DeleteOrEOF,
ansi.CTRL_H: (*Core).Backspace,
ansi.BACKSPACE: (*Core).Backspace,
ansi.CTRL_L: (*Core).Clear,
ansi.CTRL_T: (*Core).SwapChars,
ansi.CTRL_B: (*Core).MoveLeft,
ansi.CTRL_F: (*Core).MoveRight,
ansi.CTRL_P: (*Core).HistoryBack,
ansi.CTRL_N: (*Core).HistoryForward,
ansi.CTRL_U: (*Core).CutLineLeft,
ansi.CTRL_K: (*Core).CutLineRight,
ansi.CTRL_A: (*Core).MoveBeginning,
ansi.CTRL_E: (*Core).MoveEnd,
ansi.CTRL_W: (*Core).CutPrevWord,
ansi.CTRL_Y: (*Core).Paste,
// Escape sequences
ansi.START_ESCAPE_SEQ: nil,
ansi.META_B: (*Core).MoveWordLeft,
ansi.META_LEFT: (*Core).MoveWordLeft,
ansi.META_F: (*Core).MoveWordRight,
ansi.META_RIGHT: (*Core).MoveWordRight,
ansi.LEFT: (*Core).MoveLeft,
ansi.RIGHT: (*Core).MoveRight,
ansi.UP: (*Core).HistoryBack,
ansi.DOWN: (*Core).HistoryForward,
// Extended escape
ansi.START_EXTENDED_ESCAPE_SEQ: nil,
ansi.START_EXTENDED_ESCAPE_SEQ_3: nil,
ansi.DELETE: (*Core).Delete, // Delete key
}
}