forked from aaronjanse/3mux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
132 lines (111 loc) · 3.29 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"log"
"strings"
"github.com/aaronjanse/3mux/keypress"
)
// Config stores all user configuration values
type Config struct {
statusBar bool
bindings map[interface{}]string
}
var config = Config{
statusBar: true,
bindings: map[interface{}]string{
keypress.AltChar{Char: 'N'}: "newWindow",
keypress.AltChar{Char: '\n'}: "newWindow",
keypress.AltShiftChar{Char: 'F'}: "fullscreen",
keypress.AltChar{Char: 'X'}: "debugSlowMode",
keypress.AltChar{Char: '/'}: "search",
keypress.AltShiftArrow{Direction: keypress.Up}: "moveWindow(Up)",
keypress.AltShiftArrow{Direction: keypress.Down}: "moveWindow(Down)",
keypress.AltShiftArrow{Direction: keypress.Left}: "moveWindow(Left)",
keypress.AltShiftArrow{Direction: keypress.Right}: "moveWindow(Right)",
keypress.AltShiftChar{Char: 'H'}: "moveWindow(Left)",
keypress.AltShiftChar{Char: 'J'}: "moveWindow(Down)",
keypress.AltShiftChar{Char: 'K'}: "moveWindow(Up)",
keypress.AltShiftChar{Char: 'L'}: "moveWindow(Right)",
keypress.AltArrow{Direction: keypress.Up}: "moveSelection(Up)",
keypress.AltArrow{Direction: keypress.Down}: "moveSelection(Down)",
keypress.AltArrow{Direction: keypress.Left}: "moveSelection(Left)",
keypress.AltArrow{Direction: keypress.Right}: "moveSelection(Right)",
keypress.AltChar{Char: 'H'}: "moveSelection(Left)",
keypress.AltChar{Char: 'J'}: "moveSelection(Down)",
keypress.AltChar{Char: 'K'}: "moveSelection(Up)",
keypress.AltChar{Char: 'L'}: "moveSelection(Right)",
keypress.AltShiftChar{Char: 'Q'}: "killWindow",
keypress.AltChar{Char: 'R'}: "resize",
},
}
func seiveConfigEvents(ev interface{}) bool {
if operationCode, ok := config.bindings[ev]; ok {
executeOperationCode(operationCode)
root.simplify()
root.refreshRenderRect()
return true
}
return false
}
func executeOperationCode(s string) {
sections := strings.Split(s, "(")
funcName := sections[0]
var parametersText string
if len(sections) < 2 {
parametersText = ""
} else {
parametersText = strings.TrimRight(sections[1], ")")
}
params := strings.Split(parametersText, ",")
for idx, param := range params {
params[idx] = strings.TrimSpace(param)
}
if root.workspaces[root.selectionIdx].doFullscreen {
switch funcName {
case "fullscreen":
unfullscreen()
case "killWindow":
unfullscreen()
killWindow()
case "search":
search()
}
} else {
switch funcName {
case "search":
search()
case "fullscreen":
fullscreen()
case "newWindow":
newWindow()
case "moveWindow":
d := getDirectionFromString(params[0])
moveWindow(d)
case "moveSelection":
d := getDirectionFromString(params[0])
moveSelection(d)
case "killWindow":
killWindow()
case "resize":
resizeMode = true
case "debugSlowMode":
log.Println("slowmo enabled!")
if getSelection().getContainer().(*Pane).vterm.DebugSlowMode {
dbug := ""
scr := getSelection().getContainer().(*Pane).vterm.Screen
for _, row := range scr {
for _, ch := range row {
dbug += string(ch.Rune)
}
dbug += "\n"
}
log.Println("=== SCREEN OUTPUT ===")
log.Println(dbug)
getSelection().getContainer().(*Pane).vterm.DebugSlowMode = false
} else {
getSelection().getContainer().(*Pane).vterm.DebugSlowMode = true
}
default:
panic(funcName)
}
}
}