gomp/utils.go
aditya-K2 a8f6c78461 A Simple Implementation of ProgressBar
The ProgressBar is just a string which has a length equal to the
innerRect of the table. The length of the innerRect is considered to be
100% and the rest of the progress is tracked in relation to it.
The Progress is displayed with the help of the color formatting strings
in tview
       link: https://pkg.go.dev/github.com/rivo/tview#hdr-Colors

the progress length which is calculated by finding the percentage of the
innerRect that matches with the given completion and then at that length
the "[-:-:-]" is inserted with the help of the insertAt function in
utils.go. "[-:-:-]" represents resetting of colors.
2021-10-17 11:10:38 +05:30

39 lines
789 B
Go

package main
import(
"strings"
"strconv"
)
func convertToStrings(e float64) string{
a := int(e)
var min, seconds string
if (a/60 < 10){
min = "0"
min += strconv.Itoa(a/60)
} else {
min = strconv.Itoa(a/60)
}
if (a%60 < 10){
seconds = "0"
seconds += strconv.Itoa(a%60)
} else{
seconds = strconv.Itoa(a%60)
}
return min + ":" + seconds
}
func insertAt(inputString, stringTobeInserted string, index int) string{
s := inputString[:index] + stringTobeInserted + inputString[index:]
return s
}
func getText(width , percentage float64, eta string) string{
q := "[#000000:#ffffff]"
var a string
a += strings.Repeat(" ", int(width) - len(eta))
a = insertAt(a, eta, int(width/2) - 10)
a = insertAt(a, "[-:-:-]", int(width * percentage / 100))
q += a
return q
}