-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
102 lines (92 loc) · 3.11 KB
/
config.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package util
import (
"fmt"
"strings"
"golang.org/x/mobile/event/key"
)
// LoadRule describes a rule executed when right clicking on text.
//
// Concerning Action:
// - If the first character is 'X' the rest of the string will be
// interpreted as a command (possibly external) and executed
// - if the first character is 'L' the rest of the string *up to
// the first semicolon* will be interpreted as a file name to open,
// the text after the semicolon will be interpreted as an address
// expression (like those understood by Edit) and used to calculate
// the initial position of the cursor
//
// In either case expressions like $1, $2 etc... inside Action string
// will be replaced with the corrisponding matching group of Re.
//
// An 'L' type action will only succeed if the specified file exists,
// is a UTF8 file and is less than 10MB. If any of this conditions
// isn't met the rule will be considered failed and other rules will
// be evaluated.
type LoadRule struct {
BufRe string // only apply to buffers matching this regular expression
Re string // apply when this regular expression is matched
Action string // action to execute
}
type SaveRule struct {
Ext string
Cmd string
}
var keynames = map[key.Code]string{
key.CodeReturnEnter: "return",
key.CodeEscape: "escape",
key.CodeDeleteBackspace: "backspace",
key.CodeTab: "tab",
key.CodeSpacebar: "space",
key.CodeCapsLock: "caps_lock",
key.CodePause: "Pause",
key.CodeInsert: "insert",
key.CodeHome: "home",
key.CodePageUp: "prior",
key.CodeDeleteForward: "delete",
key.CodeEnd: "end",
key.CodePageDown: "next",
key.CodeRightArrow: "right_arrow",
key.CodeLeftArrow: "left_arrow",
key.CodeDownArrow: "down_arrow",
key.CodeUpArrow: "up_arrow",
key.CodeKeypadNumLock: "num_lock",
key.CodeHelp: "help",
key.CodeMute: "mute",
key.CodeVolumeUp: "up_volume",
key.CodeVolumeDown: "down_volume",
key.CodeLeftControl: "left_control",
key.CodeLeftShift: "left_shift",
key.CodeLeftAlt: "left_alt",
key.CodeLeftGUI: "Menu",
key.CodeRightControl: "right_control",
key.CodeRightShift: "right_shift",
key.CodeRightAlt: "right_alt",
key.CodeRightGUI: "Menu",
}
//control, alt, shift, super
func KeyEvent(e key.Event) string {
m := make([]string, 0, 5)
modifiers := []key.Modifiers{key.ModControl, key.ModAlt, key.ModShift, key.ModMeta}
modnames := []string{"control", "alt", "shift", "super"}
for i, k := range modifiers {
if e.Modifiers&k != 0 {
m = append(m, modnames[i])
}
}
if n, ok := keynames[e.Code]; ok {
m = append(m, n)
} else if e.Code >= key.CodeF1 && e.Code <= key.CodeF12 {
m = append(m, fmt.Sprintf("f%d", e.Code-key.CodeF1))
} else if e.Code >= key.CodeF13 && e.Code <= key.CodeF24 {
m = append(m, fmt.Sprintf("f%d", 13+(e.Code-key.CodeF13)))
} else if e.Rune > 0 {
s := string(e.Rune)
if e.Modifiers&key.ModShift != 0 {
s = strings.ToLower(s)
}
m = append(m, s)
} else {
return ""
}
return strings.Join(m, "+")
}