add block volume
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Simon Vieille 2022-08-29 13:44:34 +02:00
parent 433cfda295
commit 2a701fe19b
Signed by: deblan
GPG Key ID: 579388D585F70417
2 changed files with 54 additions and 0 deletions

View File

@ -68,6 +68,12 @@ Show indicator of RSS.
rss <block_name> <feed_url> <feed_reader_url> <foreground_color_when_no_item> <foreground_color_when_items>
```
Show volume.
```
volume <channel>
```
Toggler for wireguard.
```

48
blocks/volume/main.go Normal file
View File

@ -0,0 +1,48 @@
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)
}