From 9d1d1a02fde0a1561ad6a61e551a144bbeadc45b Mon Sep 17 00:00:00 2001 From: Simon Garrelou Date: Fri, 9 Dec 2022 15:21:04 +0100 Subject: Add play queue page --- src/page_queue.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/page_queue.go (limited to 'src/page_queue.go') diff --git a/src/page_queue.go b/src/page_queue.go new file mode 100644 index 0000000..fe8910f --- /dev/null +++ b/src/page_queue.go @@ -0,0 +1,38 @@ +package src + +import ( + "fmt" + + "github.com/rivo/tview" +) + +func (a *app) queuePage() tview.Primitive { + a.playQueueList = tview.NewList(). + ShowSecondaryText(false). + SetHighlightFullLine(true) + + a.setupMusicControlKeys(a.playQueueList.Box) + + a.updatePageQueue() + + return a.playQueueList +} + +func (a *app) updatePageQueue() { + sel := a.playQueueList.GetCurrentItem() + a.playQueueList.Clear() + + for _, song := range a.playQueue.GetSongs() { + ownSong := *song + a.playQueueList.AddItem(fmt.Sprintf("* %s - %s", song.Title, song.Artist), "", 0, func() { + a.playQueue.SkipTo(&ownSong) + a.playQueueList.SetCurrentItem(0) + }) + } + + if sel < a.playQueueList.GetItemCount() { + a.playQueueList.SetCurrentItem(sel) + } else { + a.playQueueList.SetCurrentItem(a.playQueueList.GetItemCount() - 1) + } +} -- cgit v1.2.3