Added Title To progressBar
The progressBar now has title which displays the Current Status.
This commit is contained in:
		
							parent
							
								
									7ce6def361
								
							
						
					
					
						commit
						b6133cd1c9
					
				@ -5,6 +5,7 @@ import (
 | 
				
			|||||||
	"github.com/gdamore/tcell/v2"
 | 
						"github.com/gdamore/tcell/v2"
 | 
				
			||||||
	"github.com/fhs/gompd/mpd"
 | 
						"github.com/fhs/gompd/mpd"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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
 | 
				
			||||||
@ -58,6 +59,10 @@ func (s *progressBar) updateProgress(conn mpd.Client){
 | 
				
			|||||||
	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.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 {
 | 
				
			||||||
 | 
							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.GetCell(1,0).Text = ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										16
									
								
								utils.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								utils.go
									
									
									
									
									
								
							@ -28,7 +28,7 @@ func insertAt(inputString, stringTobeInserted string, index int) string{
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getText(width , percentage float64, eta string) string{
 | 
					func getText(width , percentage float64, eta string) string{
 | 
				
			||||||
	q := "[#000000:#ffffff]"
 | 
						q := "[#000000:#ffffff:bl]"
 | 
				
			||||||
	var a string
 | 
						var a string
 | 
				
			||||||
	a += strings.Repeat(" ", int(width) - len(eta))
 | 
						a += strings.Repeat(" ", int(width) - len(eta))
 | 
				
			||||||
	a = insertAt(a, eta, int(width/2) - 10)
 | 
						a = insertAt(a, eta, int(width/2) - 10)
 | 
				
			||||||
@ -36,3 +36,17 @@ func getText(width , percentage float64, eta string) string{
 | 
				
			|||||||
	q += a
 | 
						q += a
 | 
				
			||||||
	return q
 | 
						return q
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func formatString(a interface{}) string {
 | 
				
			||||||
 | 
						if a == "play" {
 | 
				
			||||||
 | 
							return "Playing"
 | 
				
			||||||
 | 
						} else if a == "1" {
 | 
				
			||||||
 | 
							return "On"
 | 
				
			||||||
 | 
						} else if a == "0" {
 | 
				
			||||||
 | 
							return "Off"
 | 
				
			||||||
 | 
						} else if a == "stop" {
 | 
				
			||||||
 | 
							return "Stopped"
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return "Paused"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user