diff options
author | Simon Garrelou <simon@sixfoisneuf.fr> | 2022-12-06 19:26:34 +0100 |
---|---|---|
committer | Simon Garrelou <simon@sixfoisneuf.fr> | 2022-12-06 19:26:34 +0100 |
commit | f8f5ec9f3b37464094b5264954a60c551304257a (patch) | |
tree | b29526821134004cb9b1dcc074aafa1d9ee4fb53 /src/app.go | |
parent | badc7b254edb837e4338152b4acd34ab5b9b5ddd (diff) | |
download | termsonic-f8f5ec9f3b37464094b5264954a60c551304257a.tar.gz termsonic-f8f5ec9f3b37464094b5264954a60c551304257a.zip |
change focus w/ left-right, quit w/ q, F1-F3
Diffstat (limited to 'src/app.go')
-rw-r--r-- | src/app.go | 32 |
1 files changed, 28 insertions, 4 deletions
@@ -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 | ||
79 | func switchToPage(a *app, name string) { | 102 | func 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 | } |