-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
input.go
49 lines (47 loc) · 1.2 KB
/
input.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
package main
import (
"github.com/gdamore/tcell"
"log"
)
func inputLoop(s tcell.Screen, event chan<- Event) {
for {
ev := s.PollEvent()
switch ev := ev.(type) {
case *tcell.EventMouse:
switch ev.Buttons() {
case tcell.Button1:
x, y := ev.Position()
event <- Event{Type: switchState, X: x / 2, Y: y}
case tcell.Button3:
x, y := ev.Position()
event <- Event{Type: putPreset, X: x / 2, Y: y}
default:
continue
}
case *tcell.EventResize:
event <- Event{Type: resize}
case *tcell.EventKey:
if ev.Key() == tcell.KeyEnter {
log.Print("event: enter")
event <- Event{Type: step}
} else if ev.Key() == tcell.KeyEsc || ev.Key() == tcell.KeyCtrlC || ev.Rune() == 'q' {
log.Print("event: exit")
event <- Event{Type: done}
} else if ev.Rune() == ' ' {
event <- Event{Type: switchStop}
} else if ev.Rune() == 'c' {
event <- Event{Type: clear}
} else if ev.Rune() == 'p' {
event <- Event{Type: switchPreset}
} else if ev.Rune() == 'r' {
event <- Event{Type: reset}
} else if ev.Rune() == 't' {
event <- Event{Type: switchTheme}
} else if ev.Rune() == 'h' {
event <- Event{Type: switchHide}
}
default:
continue
}
}
}