diff options
Diffstat (limited to 'src/header.go')
-rw-r--r-- | src/header.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/header.go b/src/header.go new file mode 100644 index 0000000..5c85808 --- /dev/null +++ b/src/header.go | |||
@@ -0,0 +1,47 @@ | |||
1 | package src | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | |||
6 | "github.com/delucks/go-subsonic" | ||
7 | "github.com/rivo/tview" | ||
8 | ) | ||
9 | |||
10 | func (a *app) buildHeader() tview.Primitive { | ||
11 | flex := tview.NewFlex() | ||
12 | flex.SetDirection(tview.FlexColumn) | ||
13 | |||
14 | a.headerSections = tview.NewTextView(). | ||
15 | SetRegions(true). | ||
16 | SetChangedFunc(func() { | ||
17 | a.tv.Draw() | ||
18 | }). | ||
19 | SetHighlightedFunc(func(added, _, _ []string) { | ||
20 | hl := added[0] | ||
21 | cur, _ := a.pages.GetFrontPage() | ||
22 | |||
23 | if hl != cur { | ||
24 | a.switchToPage(hl) | ||
25 | } | ||
26 | }) | ||
27 | fmt.Fprintf(a.headerSections, `["artists"]F1: Artists[""] | ["playlists"]F2: Playlists[""] | ["config"]F3: Configuration[""]`) | ||
28 | |||
29 | a.headerNowPlaying = tview.NewTextView().SetTextAlign(tview.AlignRight) | ||
30 | |||
31 | flex.AddItem(a.headerSections, 0, 1, false) | ||
32 | flex.AddItem(a.headerNowPlaying, 0, 1, false) | ||
33 | |||
34 | a.playQueue.SetOnChangeCallback(func(song *subsonic.Child, isPaused bool) { | ||
35 | if song != nil { | ||
36 | symbol := ">" | ||
37 | if isPaused { | ||
38 | symbol = "||" | ||
39 | } | ||
40 | a.headerNowPlaying.SetText(fmt.Sprintf("%s %s - %s", symbol, song.Title, song.Artist)) | ||
41 | } else { | ||
42 | a.headerNowPlaying.SetText("Not playing") | ||
43 | } | ||
44 | }) | ||
45 | |||
46 | return flex | ||
47 | } | ||