diff --git a/main.go b/main.go index 7c1b602..36869de 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "github.com/aditya-K2/gomp/ui" "strconv" "time" @@ -17,7 +18,7 @@ import ( var ( CONN *mpd.Client - UI *Application + UI *ui.Application NOTIFICATION_SERVER *NotificationServer RENDERER *Renderer Volume int64 @@ -39,6 +40,7 @@ func main() { defer CONN.Close() cache.SetCacheDir(viper.GetString("CACHE_DIR")) RENDERER = newRenderer() + ui.SetRenderer(RENDERER) c, _ := CONN.CurrentSong() if len(c) != 0 { RENDERER.Start(c["file"]) @@ -46,12 +48,13 @@ func main() { RENDERER.Start("stop") } - UI = newApplication() + UI = ui.NewApplication() fileMap, err := CONN.GetFiles() dirTree := client.GenerateDirectoryTree(fileMap) client.SetConnection(CONN) + ui.SetConnection(CONN) client.UpdatePlaylist(UI.ExpandedView) _v, _ := CONN.Status() diff --git a/render.go b/render.go index 3d28ee1..3602a28 100644 --- a/render.go +++ b/render.go @@ -1,6 +1,7 @@ package main import ( + "github.com/aditya-K2/gomp/ui" "image" "os" @@ -51,7 +52,7 @@ func openImage(path string, c chan string) { if path != "stop" { extractedImage := getImagePath(path) img2, _ := GetImg(extractedImage) - im, _ = ueberzug.NewImage(img2, int(float32(IMG_X)*fw)+viper.GetInt("ADDITIONAL_PADDING_X"), int(float32(IMG_Y)*fh)+viper.GetInt("ADDITIONAL_PADDING_Y")) + im, _ = ueberzug.NewImage(img2, int(float32(ui.IMG_X)*fw)+viper.GetInt("ADDITIONAL_PADDING_X"), int(float32(ui.IMG_Y)*fh)+viper.GetInt("ADDITIONAL_PADDING_Y")) } d := <-c if im != nil { @@ -114,7 +115,7 @@ func GetImg(uri string) (image.Image, error) { } fw, fh := utils.GetFontWidth() img = resize.Resize( - uint(float32(IMG_W)*(fw+float32(viper.GetFloat64("IMAGE_WIDTH_EXTRA_X")))), uint(float32(IMG_H)*(fh+float32(viper.GetFloat64("IMAGE_WIDTH_EXTRA_Y")))), + uint(float32(ui.IMG_W)*(fw+float32(viper.GetFloat64("IMAGE_WIDTH_EXTRA_X")))), uint(float32(ui.IMG_H)*(fh+float32(viper.GetFloat64("IMAGE_WIDTH_EXTRA_Y")))), img, resize.Bilinear, ) diff --git a/app.go b/ui/app.go similarity index 94% rename from app.go rename to ui/app.go index 9ce62a2..bb86485 100644 --- a/app.go +++ b/ui/app.go @@ -1,4 +1,4 @@ -package main +package ui import ( "github.com/aditya-K2/tview" @@ -16,7 +16,7 @@ type Application struct { Pages *tview.Pages } -func newApplication() *Application { +func NewApplication() *Application { var pBar *progressBar = newProgressBar() expandedView := tview.NewTable() @@ -60,7 +60,7 @@ func newApplication() *Application { AddItem(searchBar, 3, 1, false). AddItem(sNavExpViewFlex, 0, 1, false) - mainFlex := tview.NewFlex().SetDirection(tview.FlexRow). + lex := tview.NewFlex().SetDirection(tview.FlexRow). AddItem(searchBarFlex, 0, 8, false). AddItem(pBar.t, 5, 1, false) @@ -68,7 +68,7 @@ func newApplication() *Application { expandedView.SetSelectable(true, false) rootPages := tview.NewPages() - rootPages.AddPage("Main", mainFlex, true, true) + rootPages.AddPage("Main", lex, true, true) App := tview.NewApplication() App.SetRoot(rootPages, true).SetFocus(expandedView) diff --git a/progressBar.go b/ui/progressBar.go similarity index 92% rename from progressBar.go rename to ui/progressBar.go index b321d23..7b824a2 100644 --- a/progressBar.go +++ b/ui/progressBar.go @@ -1,7 +1,8 @@ -package main +package ui import ( "fmt" + "github.com/fhs/gompd/mpd" "strconv" "github.com/aditya-K2/gomp/utils" @@ -10,7 +11,19 @@ import ( "github.com/gdamore/tcell/v2" ) -var CurrentSong string +var ( + CurrentSong string + CONN *mpd.Client + RENDERER interface{ Send(string) } +) + +func SetConnection(c *mpd.Client) { + CONN = c +} + +func SetRenderer(r interface{ Send(string) }) { + RENDERER = r +} // The progressBar is just a string which is separated by the color formatting String // for e.g