From 0b08b284ab17189de0b4de8166ad980bacf357c1 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Thu, 14 Oct 2021 22:04:16 +0530 Subject: [PATCH] Refactoring of the Components To Achieve focus functionality we need to separate each of this Components so I have extracted the Components out. --- main.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index c112f90..7766251 100644 --- a/main.go +++ b/main.go @@ -3,16 +3,59 @@ package main import ( "github.com/rivo/tview" + "log" + "github.com/fhs/gompd/mpd" + "github.com/gdamore/tcell/v2" + "fmt" ) -func main(){ - flext := tview.NewFlex().SetDirection(tview.FlexRow). - AddItem(tview.NewFlex(). - AddItem(tview.NewBox().SetBorder(true).SetTitle("Top"), 0, 1, false). - AddItem(tview.NewBox().SetBorder(true).SetTitle("Top"), 0, 2, false), 0, 7, false). - AddItem(tview.NewBox().SetBorder(true).SetTitle("Lmao"), 0, 1, false) +func getContent(row, column int) { +} - if err := tview.NewApplication().SetRoot(flext, true).Run(); err != nil { +func main(){ + // Connect to MPD server + conn, err := mpd.Dial("tcp", "localhost:6600") + if err != nil { + log.Fatalln(err) + } + defer conn.Close() + + expandedView := tview.NewTable() + Navbar := tview.NewTable().SetBorder(true) + searchBar := tview.NewBox().SetBorder(true) + progressBar := tview.NewBox().SetBorder(true) + + searchNavFlex := tview.NewFlex().SetDirection(tview.FlexRow). + AddItem(Navbar, 0, 1, false). + AddItem(searchBar, 0, 7, false) + + sNavExpViewFlex := tview.NewFlex(). + AddItem(searchNavFlex, 0, 1, false). + AddItem(expandedView, 0, 4, false) + + mainFlex := tview.NewFlex().SetDirection(tview.FlexRow). + AddItem(sNavExpViewFlex, 0, 8, false). + AddItem(progressBar, 0, 1, false) + + expandedView.SetBorderPadding(1,1,1,1).SetBorder(true) + expandedView.SetSelectable(true, false) + fmt.Println(expandedView.HasFocus()) + + a, err := conn.GetFiles() + aer := generateDirectoryTree(a); + ec := []string{"NothingHappens", "Remember When.mp3"} + + Update(*conn, aer.children, ec, expandedView) + expandedView.SetDoneFunc(func(key tcell.Key){ + if key == tcell.KeyLeft { + r, c := expandedView.GetSelection() + fmt.Println(join(ec) + expandedView.GetCell(r, c).Text) + } + }).SetSelectedFunc(func(row, column int){ + fmt.Println(join(ec) + expandedView.GetCell(row, column).Text) + }) + if err := tview.NewApplication().SetRoot(mainFlex, true).SetFocus(expandedView).Run(); err != nil { panic(err) } } +