-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.go
55 lines (50 loc) · 1.07 KB
/
keyboard.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
package main
import "github.com/nsf/termbox-go"
type keyboardEventType int
const (
// Exit stops the program
Exit keyboardEventType = 1 + iota
// UseDots switches the "graphics" to use dots
UseDots
// UseStars switches the "graphics" to use stars (asterisks)
UseStars
// IncA increases the frequency on the x axis
IncA
// DecA decreases the frequency on the x axis
DecA
// IncB increases the frequency on the y axis
IncB
// DecB decreases the frequency on the y axis
DecB
)
func listenToKeyboard(eventChan chan keyboardEventType) {
termbox.SetInputMode(termbox.InputEsc)
for {
switch ev := termbox.PollEvent(); ev.Type {
case termbox.EventKey:
switch ev.Key {
case termbox.KeyEsc:
eventChan <- Exit
default:
switch ev.Ch {
case '*':
eventChan <- UseStars
case '.':
eventChan <- UseDots
case 'q', 'Q':
eventChan <- Exit
case 'x':
eventChan <- DecA
case 'X':
eventChan <- IncA
case 'y':
eventChan <- DecB
case 'Y':
eventChan <- IncB
}
}
case termbox.EventError:
panic(ev.Err)
}
}
}