moving app.go progressbar.go to the new ui package

This commit is contained in:
aditya-K2 2021-12-22 20:39:01 +05:30
parent a54bfc4948
commit 0d9227e019
4 changed files with 27 additions and 10 deletions

View File

@ -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()

View File

@ -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,
)

View File

@ -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)

View File

@ -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