diff --git a/ui/app.go b/ui/app.go index 3dbf09b..a3125a3 100644 --- a/ui/app.go +++ b/ui/app.go @@ -1,6 +1,8 @@ package ui import ( + "fmt" + "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -16,7 +18,7 @@ var ( type Application struct { App *tview.Application Main *interactiveView - Navbar *tview.Table + NavMenu *NavMenu SearchBar *tview.Box ProgressBar *tview.Box Root *Root @@ -42,16 +44,21 @@ func NewApplication() *Application { mains.SetContextHandler(GetCurrentView().ContextHandler) mains.SetExternalCapture(GetCurrentView().ExternalInputCapture) - Navbar := tview.NewTable() + NavMenu := newNavMenu([]navItem{ + {"Albums", NewAction(func(e *tcell.EventKey) *tcell.EventKey { fmt.Println("Albums"); return nil }, nil)}, + {"Artists", NewAction(func(e *tcell.EventKey) *tcell.EventKey { fmt.Println("Artists"); return nil }, nil)}, + {"Liked Songs", NewAction(func(e *tcell.EventKey) *tcell.EventKey { fmt.Println("Liked Songs"); return nil }, nil)}, + {"Recently Played", NewAction(func(e *tcell.EventKey) *tcell.EventKey { fmt.Println("Recently Played"); return nil }, nil)}, + }) imagePreviewer := tview.NewBox() imagePreviewer.SetBorder(true) - Navbar.SetBackgroundColor(tcell.ColorDefault) + NavMenu.Table.SetBackgroundColor(tcell.ColorDefault) imagePreviewer.SetBackgroundColor(tcell.ColorDefault) - Navbar.SetBorder(true) - Navbar.SetSelectable(true, false) + NavMenu.Table.SetBorder(true) + NavMenu.Table.SetSelectable(true, false) done := func(s bool, err error) { if s { @@ -76,10 +83,11 @@ func NewApplication() *Application { } playlistNav.MapActions(map[tcell.Key]string{ tcell.KeyEnter: "openEntry", + tcell.KeyCtrlP: "playEntry", }) searchNavFlex := tview.NewFlex().SetDirection(tview.FlexRow). - AddItem(Navbar, 6, 3, false). + AddItem(NavMenu.Table, 6, 3, false). AddItem(playlistNav.Table, 0, 6, false). AddItem(imagePreviewer, 9, 3, false) @@ -102,7 +110,7 @@ func NewApplication() *Application { Ui = &Application{ App: App, Main: mains, - Navbar: Navbar, + NavMenu: NavMenu, SearchBar: searchbar, ProgressBar: pBar, Root: Main, diff --git a/ui/nav_playlist.go b/ui/nav.go similarity index 73% rename from ui/nav_playlist.go rename to ui/nav.go index bc41594..892cb49 100644 --- a/ui/nav_playlist.go +++ b/ui/nav.go @@ -6,6 +6,38 @@ import ( "github.com/rivo/tview" ) +type NavMenu struct { + Table *tview.Table + m []navItem +} + +type navItem struct { + name string + action *Action +} + +func newNavMenu(m []navItem) *NavMenu { + T := tview.NewTable() + n := &NavMenu{T, m} + T.SetDrawFunc(func(tcell.Screen, int, int, int, int) (int, int, int, int) { + for k := range n.m { + T.SetCell(k, 0, + GetCell(n.m[k].name, tcell.StyleDefault.Foreground(tcell.ColorRed))) + } + return T.GetInnerRect() + }) + T.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey { + if e.Key() == tcell.KeyEnter { + r, _ := T.GetSelection() + if r < len(n.m) { + return (*n.m[r].action).Func()(e) + } + } + return e + }) + return n +} + type PlaylistNav struct { Table *tview.Table Playlists *spt.UserPlaylists