From 4cae722a8afc0671d81f5b39ed010c8bd9c82ed1 Mon Sep 17 00:00:00 2001 From: Adriano Caloiaro Date: Tue, 18 Nov 2025 06:44:28 -0800 Subject: [PATCH] feat: move the network now to the "Now playing" title bar --- main.go | 5 +++-- views/views.go | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index fc336db..a06aece 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,6 @@ var ctx *context.AppContext const VERSION = "1.11.4" 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() } diff --git a/views/views.go b/views/views.go index 7570dcc..765a2d2 100644 --- a/views/views.go +++ b/views/views.go @@ -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)