forked from codesoap/mpq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys.go
51 lines (48 loc) · 1.14 KB
/
keys.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
package main
import "github.com/gdamore/tcell"
const keyBindingInfo = `Key bindings:
q : quit
enter : play highlighted song
space : toggle play/pause
up : highlight previous song
down : highlight next song
alt-up : move highlighted song up
alt-down: move highlighted song down
left : seek backwards 5s
right : seek forwards 5s
d : remove song from queue
c : clear queue`
func handleKeyEvents(ev *tcell.EventKey, events chan event) {
switch ev.Key() {
case tcell.KeyEnter:
events <- playHighlightedEvent
case tcell.KeyUp:
if ev.Modifiers()&tcell.ModAlt > 0 {
events <- movePrevEvent
} else {
events <- highlightPrevEvent
}
case tcell.KeyDown:
if ev.Modifiers()&tcell.ModAlt > 0 {
events <- moveNextEvent
} else {
events <- highlightNextEvent
}
case tcell.KeyLeft:
events <- seekBackwardsEvent
case tcell.KeyRight:
events <- seekForwardsEvent
case tcell.KeyRune:
// "Normal" keys are handled here.
switch ev.Rune() {
case ' ':
events <- togglePauseEvent
case 'd':
events <- deleteHighlightedEvent
case 'c':
events <- clearEvent
case 'q':
events <- quitEvent
}
}
}