-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeys.go
67 lines (62 loc) · 1.5 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import "github.com/gdamore/tcell/v2"
const keyBindingInfo = `Key bindings:
q : quit
enter : play highlighted song
space : toggle play/pause
up, k : highlight previous song
down, j : highlight next song
alt+up/k : move highlighted song up
alt+down/j: move highlighted song down
left, h : seek backwards 5s
right, l : 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:
handlePrevKey(ev, events)
case tcell.KeyDown:
handleNextKey(ev, events)
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 'h':
events <- seekBackwardsEvent
case 'j':
handleNextKey(ev, events)
case 'k':
handlePrevKey(ev, events)
case 'l':
events <- seekForwardsEvent
case 'd':
events <- deleteHighlightedEvent
case 'c':
events <- clearEvent
case 'q':
events <- quitEvent
}
}
}
func handlePrevKey(ev *tcell.EventKey, events chan event) {
if ev.Modifiers()&tcell.ModAlt > 0 {
events <- movePrevEvent
} else {
events <- highlightPrevEvent
}
}
func handleNextKey(ev *tcell.EventKey, events chan event) {
if ev.Modifiers()&tcell.ModAlt > 0 {
events <- moveNextEvent
} else {
events <- highlightNextEvent
}
}