-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathry.go
97 lines (85 loc) · 2 KB
/
ry.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
package main
import (
"fmt"
"os"
"github.com/gdamore/tcell"
)
const (
specialChars = "[]{}()/\\"
)
var (
keysEntered = NewKeyList("")
lastKey = NewKeyList("")
termEvents = make(chan tcell.Event, 500)
defaultClipboard = '_'
clipboards = map[rune][]rune{'_': []rune{}}
editorMode = "normal"
editorMessage = ""
editorMessageType = "info"
editorWidth = 0
editorHeight = 0
buffers = []*Buffer{}
screen tcell.Screen = nil
rootViewTree *ViewTree = nil
currentViewTree *ViewTree = nil
)
func main() {
if len(os.Args) == 2 && os.Args[1] == "-v" {
fmt.Println("ry v0.0.0")
os.Exit(0)
}
defer handlePanics()
initModes()
initCommands()
initConfig()
init_hooks()
init_highlighting()
init_search()
initVisual()
initTerm()
initScreen()
initTermEvents()
initBuffers()
initViews()
render()
top:
for {
select {
case ev := <-termEvents:
switch ev := ev.(type) {
case *tcell.EventKey:
if ev.Key() == tcell.KeyCtrlQ {
screen.Fini()
screen = nil
break top
/*
} else if ev.Key() == tcell.KeyEscape {
kl := k("ESC")
enter_normal_mode(current_view_tree, current_view_tree.leaf.buf, kl)
last_key = kl
keys_entered = k("")
*/
} else {
keysEntered.AddKey(NewKeyFromEvent(ev))
buf := currentViewTree.Leaf.Buf
for _, mode_name := range buf.Modes {
if matched := modeHandle(mustFindMode(mode_name), keysEntered); matched != nil {
keysEntered = k("")
lastKey = matched
continue top
}
}
if matched := modeHandle(mustFindMode(editorMode), keysEntered); matched != nil {
keysEntered = k("")
lastKey = matched
continue top
}
}
case *tcell.EventResize:
editorWidth, editorHeight = screen.Size()
}
default:
render()
}
}
}