Making r (Renderer) Global RENDERER

This commit is contained in:
aditya-K2 2021-12-22 17:54:14 +05:30
parent 7bb59ef102
commit d1306f194f
3 changed files with 12 additions and 11 deletions

4
app.go
View File

@ -16,9 +16,9 @@ type Application struct {
Pages *tview.Pages Pages *tview.Pages
} }
func newApplication(r *Renderer) *Application { func newApplication() *Application {
var pBar *progressBar = newProgressBar(r) var pBar *progressBar = newProgressBar()
expandedView := tview.NewTable() expandedView := tview.NewTable()
Navbar := tview.NewTable() Navbar := tview.NewTable()
searchBar := tview.NewInputField() searchBar := tview.NewInputField()

View File

@ -18,6 +18,7 @@ var (
CONN *mpd.Client CONN *mpd.Client
UI *Application UI *Application
NOTIFICATION_SERVER *NotificationServer NOTIFICATION_SERVER *NotificationServer
RENDERER *Renderer
Volume int64 Volume int64
Random bool Random bool
Repeat bool Repeat bool
@ -36,15 +37,15 @@ func main() {
} }
defer CONN.Close() defer CONN.Close()
cache.SetCacheDir(viper.GetString("CACHE_DIR")) cache.SetCacheDir(viper.GetString("CACHE_DIR"))
r := newRenderer() RENDERER = newRenderer()
c, _ := CONN.CurrentSong() c, _ := CONN.CurrentSong()
if len(c) != 0 { if len(c) != 0 {
r.Start(c["file"]) RENDERER.Start(c["file"])
} else { } else {
r.Start("stop") RENDERER.Start("stop")
} }
UI = newApplication(r) UI = newApplication()
fileMap, err := CONN.GetFiles() fileMap, err := CONN.GetFiles()
dirTree := generateDirectoryTree(fileMap) dirTree := generateDirectoryTree(fileMap)

View File

@ -26,7 +26,7 @@ type progressBar struct {
// This Function returns a progressBar with a table of two rows // This Function returns a progressBar with a table of two rows
// the First row will contain information about the current Song // the First row will contain information about the current Song
// and the Second one will contain the progressBar // and the Second one will contain the progressBar
func newProgressBar(r *Renderer) *progressBar { func newProgressBar() *progressBar {
p := progressBar{} p := progressBar{}
a := tview.NewTable(). a := tview.NewTable().
@ -38,7 +38,7 @@ func newProgressBar(r *Renderer) *progressBar {
a.SetBorder(true) a.SetBorder(true)
a.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) { a.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
p.updateTitle(r) p.updateTitle()
p.updateProgress() p.updateProgress()
return p.t.GetInnerRect() return p.t.GetInnerRect()
}) })
@ -49,16 +49,16 @@ func newProgressBar(r *Renderer) *progressBar {
return &p return &p
} }
func (s *progressBar) updateTitle(r *Renderer) { func (s *progressBar) updateTitle() {
_currentAttributes, err := CONN.CurrentSong() _currentAttributes, err := CONN.CurrentSong()
if err == nil { if err == nil {
song := "[green::bi]" + _currentAttributes["Title"] + "[-:-:-] - " + "[blue::b]" + _currentAttributes["Artist"] + "\n" song := "[green::bi]" + _currentAttributes["Title"] + "[-:-:-] - " + "[blue::b]" + _currentAttributes["Artist"] + "\n"
s.t.GetCell(0, 0).Text = song s.t.GetCell(0, 0).Text = song
if len(_currentAttributes) == 0 && CurrentSong != "" { if len(_currentAttributes) == 0 && CurrentSong != "" {
CurrentSong = "" CurrentSong = ""
r.Send("stop") RENDERER.Send("stop")
} else if song != CurrentSong && len(_currentAttributes) != 0 { } else if song != CurrentSong && len(_currentAttributes) != 0 {
r.Send(_currentAttributes["file"]) RENDERER.Send(_currentAttributes["file"])
CurrentSong = song CurrentSong = song
} }
} }