49 lines
852 B
Go
49 lines
852 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
r "gitnet.fr/deblan/i3-blocks-go/rendering"
|
||
|
"os"
|
||
|
"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 := os.Args[1]
|
||
|
|
||
|
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)
|
||
|
}
|