Clean up elapsed time calculation

This commit is contained in:
Adriano Caloiaro 2020-05-06 08:31:51 -04:00
parent 3d5f598679
commit 7a61c50c3f
No known key found for this signature in database
GPG key ID: 9FFD0E7601F166AB

View file

@ -71,16 +71,21 @@ func (n *NowPlayingView) Draw(screen tcell.Screen) {
line = fmt.Sprintf("%s[white] %s", "Track:", n.Track.Title)
tview.Print(screen, line, x, y+2, width, tview.AlignLeft, tcell.ColorBlue)
var minutes, seconds int
if n.Elapsed > 0 {
minutes = int(n.Elapsed / 60)
seconds = int(n.Elapsed) % 60
}
elapsedStr := fmt.Sprintf("%02d:%02d", minutes, seconds)
line = fmt.Sprintf("%s[white] %s", "Elapsed:", elapsedStr)
line = fmt.Sprintf("%s[white] %s", "Elapsed:", n.elapsedString())
tview.Print(screen, line, x, y+3, width, tview.AlignLeft, tcell.ColorBlue)
}
func (n *NowPlayingView) elapsedString() (str string) {
if n.Elapsed >= 0 {
minutes := int(n.Elapsed / 60)
seconds := int(n.Elapsed) % 60
str = fmt.Sprintf("%02d:%02d", minutes, seconds)
}
return
}
// Draw draws a NowPlayingView onto the scren
func (s *StatusView) Draw(screen tcell.Screen) {