aboutsummaryrefslogtreecommitdiff
path: root/src/app.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.go')
-rw-r--r--src/app.go32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/app.go b/src/app.go
index 58fc0db..c7e38a6 100644
--- a/src/app.go
+++ b/src/app.go
@@ -5,6 +5,7 @@ import (
5 "os" 5 "os"
6 6
7 "github.com/delucks/go-subsonic" 7 "github.com/delucks/go-subsonic"
8 "github.com/gdamore/tcell/v2"
8 "github.com/rivo/tview" 9 "github.com/rivo/tview"
9) 10)
10 11
@@ -38,7 +39,7 @@ func Run(cfg *Config) {
38 SetChangedFunc(func() { 39 SetChangedFunc(func() {
39 a.tv.Draw() 40 a.tv.Draw()
40 }). 41 }).
41 SetHighlightedFunc(func(added, removed, remaining []string) { 42 SetHighlightedFunc(func(added, _, _ []string) {
42 hl := added[0] 43 hl := added[0]
43 cur, _ := a.pages.GetFrontPage() 44 cur, _ := a.pages.GetFrontPage()
44 45
@@ -70,6 +71,28 @@ func Run(cfg *Config) {
70 } 71 }
71 } 72 }
72 73
74 // Keyboard shortcuts
75 a.tv.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
76 switch event.Key() {
77 case tcell.KeyF1:
78 switchToPage(a, "artists")
79 return nil
80 case tcell.KeyF2:
81 switchToPage(a, "playlists")
82 return nil
83 case tcell.KeyF3:
84 switchToPage(a, "config")
85 return nil
86 }
87
88 switch event.Rune() {
89 case 'q':
90 a.tv.Stop()
91 }
92
93 return event
94 })
95
73 if err := a.tv.SetRoot(mainLayout, true).EnableMouse(true).SetFocus(mainLayout).Run(); err != nil { 96 if err := a.tv.SetRoot(mainLayout, true).EnableMouse(true).SetFocus(mainLayout).Run(); err != nil {
74 fmt.Printf("Error running termsonic: %v", err) 97 fmt.Printf("Error running termsonic: %v", err)
75 os.Exit(1) 98 os.Exit(1)
@@ -77,13 +100,14 @@ func Run(cfg *Config) {
77} 100}
78 101
79func switchToPage(a *app, name string) { 102func switchToPage(a *app, name string) {
80 if name == "artists" { 103 switch name {
104 case "artists":
81 a.pages.SwitchToPage("artists") 105 a.pages.SwitchToPage("artists")
82 a.header.Highlight("artists") 106 a.header.Highlight("artists")
83 } else if name == "playlists" { 107 case "playlists":
84 a.pages.SwitchToPage("playlists") 108 a.pages.SwitchToPage("playlists")
85 a.header.Highlight("playlists") 109 a.header.Highlight("playlists")
86 } else if name == "config" { 110 case "config":
87 a.pages.SwitchToPage("config") 111 a.pages.SwitchToPage("config")
88 a.header.Highlight("config") 112 a.header.Highlight("config")
89 } 113 }