move the network now to the "Now playing" title bar

This commit is contained in:
Adriano Caloiaro 2025-11-18 06:44:28 -08:00
parent 40539d2a65
commit fb0faf2da5
No known key found for this signature in database
GPG key ID: C2BC56DE73CE3F75
2 changed files with 20 additions and 10 deletions

View file

@ -23,7 +23,6 @@ var ctx *context.AppContext
const VERSION = "1.11.3"
func main() {
ctx = context.CreateAppContext(views.CreateViewContext())
var err error
usernameFlag := pflag.String("username", "", "your di.fm username")
passwordFlag := pflag.String("password", "", "your di.fm password")
@ -36,7 +35,7 @@ func main() {
fmt.Printf("di-tui %s\n", VERSION)
return
}
ctx.Network, err = difm.GetNetwork(*networkFlag)
network, err := difm.GetNetwork(*networkFlag)
if err != nil {
var networks []string
for network := range difm.Networks {
@ -61,7 +60,9 @@ func main() {
os.Exit(1)
}
ctx = context.CreateAppContext(views.CreateViewContext(network))
ctx.DifmToken = token
ctx.Network = network
run()
}

View file

@ -20,6 +20,14 @@ var (
secondaryTextColor tcell.Color
)
const (
channelListTitle = " Channels "
favoritesTitle = " Favorites "
keyboardControlsTitle = " Keyboard Controls "
nowPlayingTitle = " Now Playing"
statusTitle = " Status "
)
func init() {
if config.HasTheme() {
os.Setenv("COLORTERM", "24bit")
@ -70,6 +78,7 @@ type NowPlayingView struct {
Art string
Channel *components.ChannelItem
Elapsed float64
Network *components.Network
Track components.Track
}
@ -80,13 +89,13 @@ type StatusView struct {
}
// CreateViewContext creates the primary application view of di-tui
func CreateViewContext() *ViewContext {
func CreateViewContext(network *components.Network) *ViewContext {
return &ViewContext{
App: tview.NewApplication(),
ChannelList: createChannelList(),
FavoriteList: createFavoriteList(),
Keybindings: createKeybindings(),
NowPlaying: createNowPlaying(),
NowPlaying: createNowPlaying(network),
Status: createStatusView(),
}
}
@ -172,7 +181,7 @@ func createChannelList() *tview.List {
list.
ShowSecondaryText(false).
SetBorder(true).
SetTitle(" Channels ").
SetTitle(channelListTitle).
SetTitleColor(primaryTextColor).
SetBorderColor(primaryColor)
@ -188,7 +197,7 @@ func createFavoriteList() *tview.List {
ShowSecondaryText(false).
SetBorder(true).
SetBorderColor(primaryColor).
SetTitle(" Favorites ").
SetTitle(favoritesTitle).
SetTitleColor(primaryTextColor)
list.Box.SetBackgroundColor(backgroundColor)
@ -203,21 +212,21 @@ func createKeybindings() *KeybindingView {
SetBorder(true).
SetBorderColor(primaryColor).
SetTitleColor(primaryTextColor).
SetTitle(" Keyboard Controls ")
SetTitle(keyboardControlsTitle)
kbv.SetBorderColor(primaryColor)
return kbv
}
func createNowPlaying() *NowPlayingView {
func createNowPlaying(network *components.Network) *NowPlayingView {
np := &NowPlayingView{
Box: tview.NewBox(),
Channel: &components.ChannelItem{},
Elapsed: 0.0,
}
np.SetTitle(" Now Playing ").
np.SetTitle(fmt.Sprintf("%s | %s ", nowPlayingTitle, network.Name)).
SetBorder(true).
SetBorderColor(primaryColor).
SetTitleColor(primaryTextColor)
@ -230,7 +239,7 @@ func createStatusView() *StatusView {
Box: tview.NewBox(),
Message: "Ready to Play",
}
sv.SetTitle(" Status ")
sv.SetTitle(statusTitle)
sv.SetTitleColor(primaryTextColor)
sv.SetBorder(true)
sv.SetBorderColor(primaryColor)