This commit is contained in:
parent
433cfda295
commit
2a701fe19b
|
@ -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
48
blocks/volume/main.go
Normal 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)
|
||||
}
|
Loading…
Reference in a new issue