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 | |
parent | badc7b254edb837e4338152b4acd34ab5b9b5ddd (diff) | |
download | termsonic-f8f5ec9f3b37464094b5264954a60c551304257a.tar.gz termsonic-f8f5ec9f3b37464094b5264954a60c551304257a.zip |
change focus w/ left-right, quit w/ q, F1-F3
-rw-r--r-- | src/app.go | 32 | ||||
-rw-r--r-- | src/page_artists.go | 19 |
2 files changed, 47 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 | } |
diff --git a/src/page_artists.go b/src/page_artists.go index c064785..0e1cc72 100644 --- a/src/page_artists.go +++ b/src/page_artists.go | |||
@@ -18,6 +18,7 @@ func artistsPage(a *app) tview.Primitive { | |||
18 | SetColumns(40, 0). | 18 | SetColumns(40, 0). |
19 | SetBorders(true) | 19 | SetBorders(true) |
20 | 20 | ||
21 | // Artist & album list | ||
21 | root := tview.NewTreeNode("Subsonic server").SetColor(tcell.ColorYellow) | 22 | root := tview.NewTreeNode("Subsonic server").SetColor(tcell.ColorYellow) |
22 | a.artistsTree = tview.NewTreeView(). | 23 | a.artistsTree = tview.NewTreeView(). |
23 | SetRoot(root). | 24 | SetRoot(root). |
@@ -38,9 +39,27 @@ func artistsPage(a *app) tview.Primitive { | |||
38 | a.tv.SetFocus(a.songsList) | 39 | a.tv.SetFocus(a.songsList) |
39 | }) | 40 | }) |
40 | 41 | ||
42 | // Songs list for the selected album | ||
41 | a.songsList = tview.NewList() | 43 | a.songsList = tview.NewList() |
42 | a.songsList.ShowSecondaryText(false) | 44 | a.songsList.ShowSecondaryText(false) |
43 | 45 | ||
46 | // Change the left-right keys to switch between the panels | ||
47 | a.artistsTree.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { | ||
48 | if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight { | ||
49 | a.tv.SetFocus(a.songsList) | ||
50 | return nil | ||
51 | } | ||
52 | return event | ||
53 | }) | ||
54 | |||
55 | a.songsList.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { | ||
56 | if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight { | ||
57 | a.tv.SetFocus(a.artistsTree) | ||
58 | return nil | ||
59 | } | ||
60 | return event | ||
61 | }) | ||
62 | |||
44 | grid.AddItem(a.artistsTree, 0, 0, 1, 1, 0, 0, true) | 63 | grid.AddItem(a.artistsTree, 0, 0, 1, 1, 0, 0, true) |
45 | grid.AddItem(a.songsList, 0, 1, 1, 2, 0, 0, false) | 64 | grid.AddItem(a.songsList, 0, 1, 1, 2, 0, 0, false) |
46 | 65 | ||