i3-blocks-go/blocks/volume/main.go
Simon Vieille 79fe14e059
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
use flag instead os os.Args
2022-08-30 15:42:28 +02:00

50 lines
906 B
Go

package main
import (
"flag"
"fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os/exec"
"regexp"
"strconv"
)
func Volume(channel string) int {
output, _ := exec.Command("amixer", "get", channel).Output()
regex, _ := regexp.Compile(`\[(\d+)%\]`)
data := regex.FindStringSubmatch(string(output))
volume, _ := strconv.Atoi(data[1])
return volume
}
func main() {
argChannel := flag.String("channel", "Master", "the channel")
flag.Parse()
volume := Volume(*argChannel)
var symbole string
if volume == 0 {
symbole = "\uf026"
} else if volume < 50 {
symbole = "\uf027"
} else {
symbole = "\uf028"
}
value := r.TextWithPadding(fmt.Sprintf("%d%% %s", volume, r.FontAwesome(symbole)), r.FB{
Foreground: r.Color("grey1"),
Background: r.Color("black1"),
})
options := r.NewBlockOptions()
options.FullText = value
block := r.Block("volume", options)
fmt.Println(block)
}