Making r (Renderer) Global RENDERER
This commit is contained in:
parent
7bb59ef102
commit
d1306f194f
4
app.go
4
app.go
@ -16,9 +16,9 @@ type Application struct {
|
||||
Pages *tview.Pages
|
||||
}
|
||||
|
||||
func newApplication(r *Renderer) *Application {
|
||||
func newApplication() *Application {
|
||||
|
||||
var pBar *progressBar = newProgressBar(r)
|
||||
var pBar *progressBar = newProgressBar()
|
||||
expandedView := tview.NewTable()
|
||||
Navbar := tview.NewTable()
|
||||
searchBar := tview.NewInputField()
|
||||
|
9
main.go
9
main.go
@ -18,6 +18,7 @@ var (
|
||||
CONN *mpd.Client
|
||||
UI *Application
|
||||
NOTIFICATION_SERVER *NotificationServer
|
||||
RENDERER *Renderer
|
||||
Volume int64
|
||||
Random bool
|
||||
Repeat bool
|
||||
@ -36,15 +37,15 @@ func main() {
|
||||
}
|
||||
defer CONN.Close()
|
||||
cache.SetCacheDir(viper.GetString("CACHE_DIR"))
|
||||
r := newRenderer()
|
||||
RENDERER = newRenderer()
|
||||
c, _ := CONN.CurrentSong()
|
||||
if len(c) != 0 {
|
||||
r.Start(c["file"])
|
||||
RENDERER.Start(c["file"])
|
||||
} else {
|
||||
r.Start("stop")
|
||||
RENDERER.Start("stop")
|
||||
}
|
||||
|
||||
UI = newApplication(r)
|
||||
UI = newApplication()
|
||||
|
||||
fileMap, err := CONN.GetFiles()
|
||||
dirTree := generateDirectoryTree(fileMap)
|
||||
|
@ -26,7 +26,7 @@ type progressBar struct {
|
||||
// This Function returns a progressBar with a table of two rows
|
||||
// the First row will contain information about the current Song
|
||||
// and the Second one will contain the progressBar
|
||||
func newProgressBar(r *Renderer) *progressBar {
|
||||
func newProgressBar() *progressBar {
|
||||
p := progressBar{}
|
||||
|
||||
a := tview.NewTable().
|
||||
@ -38,7 +38,7 @@ func newProgressBar(r *Renderer) *progressBar {
|
||||
a.SetBorder(true)
|
||||
|
||||
a.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||
p.updateTitle(r)
|
||||
p.updateTitle()
|
||||
p.updateProgress()
|
||||
return p.t.GetInnerRect()
|
||||
})
|
||||
@ -49,16 +49,16 @@ func newProgressBar(r *Renderer) *progressBar {
|
||||
return &p
|
||||
}
|
||||
|
||||
func (s *progressBar) updateTitle(r *Renderer) {
|
||||
func (s *progressBar) updateTitle() {
|
||||
_currentAttributes, err := CONN.CurrentSong()
|
||||
if err == nil {
|
||||
song := "[green::bi]" + _currentAttributes["Title"] + "[-:-:-] - " + "[blue::b]" + _currentAttributes["Artist"] + "\n"
|
||||
s.t.GetCell(0, 0).Text = song
|
||||
if len(_currentAttributes) == 0 && CurrentSong != "" {
|
||||
CurrentSong = ""
|
||||
r.Send("stop")
|
||||
RENDERER.Send("stop")
|
||||
} else if song != CurrentSong && len(_currentAttributes) != 0 {
|
||||
r.Send(_currentAttributes["file"])
|
||||
RENDERER.Send(_currentAttributes["file"])
|
||||
CurrentSong = song
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user