Minor Changes to ProgressBar
Some Information from the ProgressBar has been removed.
This commit is contained in:
parent
c3ede5403e
commit
9e69ed9f1e
@ -1,11 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rivo/tview"
|
|
||||||
"github.com/gdamore/tcell/v2"
|
|
||||||
"github.com/fhs/gompd/mpd"
|
|
||||||
"strconv"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/fhs/gompd/mpd"
|
||||||
|
"github.com/gdamore/tcell/v2"
|
||||||
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The progressBar is just a string which is separated by the color formatting String
|
// The progressBar is just a string which is separated by the color formatting String
|
||||||
@ -18,7 +19,7 @@ import (
|
|||||||
// colored background. this is done by calculating the innerRect of the table and taking that length as
|
// colored background. this is done by calculating the innerRect of the table and taking that length as
|
||||||
// 100% and then representing the rest of the information in relation to it
|
// 100% and then representing the rest of the information in relation to it
|
||||||
|
|
||||||
type progressBar struct{
|
type progressBar struct {
|
||||||
t *tview.Table
|
t *tview.Table
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,12 +30,12 @@ func newProgressBar(conn mpd.Client) *progressBar {
|
|||||||
p := progressBar{}
|
p := progressBar{}
|
||||||
|
|
||||||
a := tview.NewTable().
|
a := tview.NewTable().
|
||||||
SetCell(0, 0, tview.NewTableCell("")).
|
SetCell(0, 0, tview.NewTableCell("")).
|
||||||
SetCell(1, 0, tview.NewTableCell(""))
|
SetCell(1, 0, tview.NewTableCell(""))
|
||||||
|
|
||||||
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(conn)
|
p.updateTitle(conn)
|
||||||
p.updateProgress(conn)
|
p.updateProgress(conn)
|
||||||
return p.t.GetInnerRect()
|
return p.t.GetInnerRect()
|
||||||
@ -45,24 +46,24 @@ func newProgressBar(conn mpd.Client) *progressBar {
|
|||||||
return &p
|
return &p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *progressBar) updateTitle(conn mpd.Client){
|
func (s *progressBar) updateTitle(conn mpd.Client) {
|
||||||
_currentAttributes, err := conn.CurrentSong()
|
_currentAttributes, err := conn.CurrentSong()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
s.t.GetCell(0,0).Text = _currentAttributes["Artist"] + " - " +_currentAttributes["Title"]
|
s.t.GetCell(0, 0).Text = _currentAttributes["Artist"] + " - " + _currentAttributes["Title"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *progressBar) updateProgress(conn mpd.Client){
|
func (s *progressBar) updateProgress(conn mpd.Client) {
|
||||||
_status,err := conn.Status()
|
_status, err := conn.Status()
|
||||||
_, _, _width, _ := s.t.GetInnerRect()
|
_, _, _width, _ := s.t.GetInnerRect()
|
||||||
el, err1 := strconv.ParseFloat(_status["elapsed"], 8)
|
el, err1 := strconv.ParseFloat(_status["elapsed"], 8)
|
||||||
du , err := strconv.ParseFloat(_status["duration"], 8)
|
du, err := strconv.ParseFloat(_status["duration"], 8)
|
||||||
percentage := el / du * 100
|
percentage := el / du * 100
|
||||||
if err == nil && err1 == nil{
|
if err == nil && err1 == nil {
|
||||||
s.t.SetTitle(fmt.Sprintf("[[::i] %s [-:-:-]Shuffle: %s Repeat: %s Single: %s Volume: %s ]", formatString(_status["state"]),formatString(_status["random"]), formatString(_status["repeat"]), formatString(_status["single"]), _status["volume"] )).SetTitleAlign(tview.AlignRight)
|
s.t.SetTitle(fmt.Sprintf("[[::i] %s [-:-:-]Shuffle: %s Repeat: %s Volume: %s ]", formatString(_status["state"]), formatString(_status["random"]), formatString(_status["repeat"]), _status["volume"])).SetTitleAlign(tview.AlignRight)
|
||||||
s.t.GetCell(1,0).Text = getText(float64(_width), percentage, strTime(el) + "/" + strTime(du) + "(" + strconv.FormatFloat(percentage, 'f', 2, 32) + "%" + ")")
|
s.t.GetCell(1, 0).Text = getText(float64(_width), percentage, strTime(el)+"/"+strTime(du)+"("+strconv.FormatFloat(percentage, 'f', 2, 32)+"%"+")")
|
||||||
} else {
|
} else {
|
||||||
s.t.SetTitle(fmt.Sprintf("[[::i] %s [-:-:-]Shuffle: %s Repeat: %s Single: %s]", formatString(_status["state"]),formatString(_status["random"]), formatString(_status["repeat"]), formatString(_status["single"]))).SetTitleAlign(tview.AlignRight)
|
s.t.SetTitle(fmt.Sprintf("[[::i] %s [-:-:-]Shuffle: %s Repeat: %s]", formatString(_status["state"]), formatString(_status["random"]), formatString(_status["repeat"]))).SetTitleAlign(tview.AlignRight)
|
||||||
s.t.GetCell(1,0).Text = ""
|
s.t.GetCell(1, 0).Text = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user