2021-10-17 05:40:38 +00:00
|
|
|
package main
|
2021-10-17 16:56:26 +00:00
|
|
|
|
|
|
|
import (
|
2021-10-29 08:16:18 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2021-10-17 05:40:38 +00:00
|
|
|
"strconv"
|
2021-10-17 16:56:26 +00:00
|
|
|
"strings"
|
2021-10-29 04:38:09 +00:00
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
2021-10-17 05:40:38 +00:00
|
|
|
)
|
|
|
|
|
2021-10-29 04:38:09 +00:00
|
|
|
type winsize struct {
|
|
|
|
Row uint16
|
|
|
|
Col uint16
|
|
|
|
Xpixel uint16
|
|
|
|
Ypixel uint16
|
|
|
|
}
|
|
|
|
|
|
|
|
func getWidth() *winsize {
|
|
|
|
ws := &winsize{}
|
|
|
|
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
|
|
|
|
uintptr(syscall.Stdin),
|
|
|
|
uintptr(syscall.TIOCGWINSZ),
|
|
|
|
uintptr(unsafe.Pointer(ws)))
|
|
|
|
|
|
|
|
if int(retCode) == -1 {
|
|
|
|
panic(errno)
|
|
|
|
}
|
|
|
|
return ws
|
|
|
|
}
|
|
|
|
|
|
|
|
func getFontWidth() (float32, float32) {
|
|
|
|
g := getWidth()
|
|
|
|
fw := (float32(g.Xpixel) / float32(g.Col))
|
|
|
|
fh := (float32(g.Ypixel) / float32(g.Row))
|
|
|
|
return fw, fh
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:56:26 +00:00
|
|
|
func strTime(e float64) string {
|
2021-10-17 05:40:38 +00:00
|
|
|
a := int(e)
|
|
|
|
var min, seconds string
|
2021-10-17 16:56:26 +00:00
|
|
|
if a/60 < 10 {
|
2021-10-17 05:40:38 +00:00
|
|
|
min = "0"
|
2021-10-17 16:56:26 +00:00
|
|
|
min += strconv.Itoa(a / 60)
|
2021-10-17 05:40:38 +00:00
|
|
|
} else {
|
2021-10-17 16:56:26 +00:00
|
|
|
min = strconv.Itoa(a / 60)
|
2021-10-17 05:40:38 +00:00
|
|
|
}
|
2021-10-17 16:56:26 +00:00
|
|
|
if a%60 < 10 {
|
2021-10-17 05:40:38 +00:00
|
|
|
seconds = "0"
|
2021-10-17 16:56:26 +00:00
|
|
|
seconds += strconv.Itoa(a % 60)
|
|
|
|
} else {
|
|
|
|
seconds = strconv.Itoa(a % 60)
|
2021-10-17 05:40:38 +00:00
|
|
|
}
|
|
|
|
return min + ":" + seconds
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:56:26 +00:00
|
|
|
func insertAt(inputString, stringTobeInserted string, index int) string {
|
|
|
|
s := inputString[:index] + stringTobeInserted + inputString[index:]
|
2021-10-17 05:40:38 +00:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:56:26 +00:00
|
|
|
func getText(width, percentage float64, eta string) string {
|
|
|
|
q := "[#000000:#ffffff:b]"
|
2021-10-17 05:40:38 +00:00
|
|
|
var a string
|
2021-10-17 16:56:26 +00:00
|
|
|
a += strings.Repeat(" ", int(width)-len(eta))
|
|
|
|
a = insertAt(a, eta, int(width/2)-10)
|
|
|
|
a = insertAt(a, "[-:-:-]", int(width*percentage/100))
|
2021-10-17 05:40:38 +00:00
|
|
|
q += a
|
|
|
|
return q
|
|
|
|
}
|
2021-10-17 07:45:52 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
}
|
2021-10-29 08:16:18 +00:00
|
|
|
|
|
|
|
func getMusicDirectory() string {
|
2021-11-05 07:10:46 +00:00
|
|
|
content, err := ioutil.ReadFile(HOME_DIR + "/.config/mpd/mpd.conf")
|
2021-10-29 08:16:18 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println("No Config File for mpd Found")
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
ab := string(content)
|
|
|
|
maps := strings.Split(ab, "\n")
|
|
|
|
for _, j := range maps {
|
|
|
|
if strings.Contains(j, "music_directory") {
|
|
|
|
s := strings.SplitAfter(strings.ReplaceAll(j, " ", ""), "y")[1]
|
|
|
|
d := ""
|
|
|
|
for z, m := range s {
|
|
|
|
if (z != 0) && (z != (len(s) - 1)) {
|
|
|
|
d += string(m)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|