-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathparser.go
52 lines (48 loc) · 1.09 KB
/
parser.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
package main
import (
"sync"
"github.com/gdamore/tcell/v2"
"github.com/viktomas/godu/commands"
)
func parseCommand(s tcell.Screen, commandsChan chan commands.Executer, wg *sync.WaitGroup) {
defer wg.Done()
for {
ev := s.PollEvent()
switch ev := ev.(type) {
case *tcell.EventKey:
switch ev.Key() {
case tcell.KeyEscape, tcell.KeyCtrlC:
close(commandsChan)
return
case tcell.KeyEnter, tcell.KeyRight:
commandsChan <- commands.Enter{}
case tcell.KeyDown:
commandsChan <- commands.Down{}
case tcell.KeyUp:
commandsChan <- commands.Up{}
case tcell.KeyBackspace, tcell.KeyLeft:
commandsChan <- commands.GoBack{}
case tcell.KeyCtrlL:
s.Sync()
case tcell.KeyRune:
switch ev.Rune() {
case ' ':
commandsChan <- commands.Mark{}
case 'q':
close(commandsChan)
return
case 'h':
commandsChan <- commands.GoBack{}
case 'j':
commandsChan <- commands.Down{}
case 'k':
commandsChan <- commands.Up{}
case 'l':
commandsChan <- commands.Enter{}
}
}
case *tcell.EventResize:
s.Sync()
}
}
}