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
|
package src
import (
"fmt"
"github.com/delucks/go-subsonic"
"github.com/rivo/tview"
)
func (a *app) buildHeader() tview.Primitive {
flex := tview.NewFlex()
flex.SetDirection(tview.FlexColumn)
a.headerSections = tview.NewTextView().
SetRegions(true).
SetChangedFunc(func() {
a.tv.Draw()
}).
SetHighlightedFunc(func(added, _, _ []string) {
hl := added[0]
cur, _ := a.pages.GetFrontPage()
if hl != cur {
a.switchToPage(hl)
}
})
fmt.Fprintf(a.headerSections, `["artists"]F1: Artists[""] | ["playqueue"]F2: Queue[""] | ["playlists"]F3: Playlists[""] | ["config"]F4: Configuration[""]`)
a.headerNowPlaying = tview.NewTextView().SetTextAlign(tview.AlignRight)
flex.AddItem(a.headerSections, 0, 1, false)
flex.AddItem(a.headerNowPlaying, 0, 1, false)
a.playQueue.SetOnChangeCallback(func(song *subsonic.Child, isPaused bool) {
if song != nil {
symbol := ">"
if isPaused {
symbol = "||"
}
a.headerNowPlaying.SetText(fmt.Sprintf("%s %s - %s", symbol, song.Title, song.Artist))
} else {
a.headerNowPlaying.SetText("Not playing")
}
a.updatePageQueue()
// Fix "Now Playing" not always updating
go a.tv.Draw()
})
return flex
}
|