breto

A status bar written in Go.
Log | Files | Refs | README | LICENSE

commit f78de857c80914eb9034837c2d4396f9192022d6
parent 9acba1eb1bbc3e9157e645114602eba3d88cf405
Author: J. R. Swab <jrswab@protonmail.com>
Date:   Tue,  4 Jun 2019 01:19:48 +0000

Merge branch 'volPercent' into 'master'

Added volume percent number

See merge request jrswab/go-status!13
Diffstat:
Ablocks/volume.go | 18++++++++++++++++++
Ablocks/volume_test.go | 14++++++++++++++
Mmain.go | 16+++++++++-------
3 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/blocks/volume.go b/blocks/volume.go @@ -0,0 +1,18 @@ +package blocks + +import ( + "fmt" + "os/exec" + "strings" +) + +func VolumeText() (string, error) { + volCmd := "amixer -D pulse sget Master | awk '/Front Right:/ {print $5}' | grep -o '[0-9].'" + runVol, err := exec.Command("sh", "-c", volCmd).Output() + if err != nil { + return "", err + } + + percent := "%" + return fmt.Sprintf("%s%s | ", strings.TrimSpace(string(runVol)), percent), nil +} diff --git a/blocks/volume_test.go b/blocks/volume_test.go @@ -0,0 +1,14 @@ +package blocks + +import ( + "fmt" + "testing" +) + +func TestVolumeText(t *testing.T) { + vol, err := VolumeText() + if err != nil { + t.Error(err) + } + fmt.Println(vol) +} diff --git a/main.go b/main.go @@ -9,11 +9,9 @@ import ( ) func main() { - var status, hTime, weather, ramFree string + // Other Blocks: + var status, hTime, weather, ramFree, rShift, dropbox, volIcon, volText string var wttrErr, ramErr error - volume, _ := blocks.VolumeIcon() - redshift, _ := blocks.RedshiftIcon() - dropbox, _ := blocks.DropboxIcon() cWttr := make(chan string) // start weather data routine eWttr := make(chan error) @@ -38,11 +36,15 @@ func main() { default: } - volume, _ = blocks.VolumeIcon() - redshift, _ = blocks.RedshiftIcon() + // Assign Icons & non Go Routine blocks every round + rShift, _ = blocks.RedshiftIcon() dropbox, _ = blocks.DropboxIcon() + volText, _ = blocks.VolumeText() + volIcon, _ = blocks.VolumeIcon() + // Change by editing variables & `%s` - status = fmt.Sprintf(" %s%s%s %s%s%s ", ramFree, weather, hTime, dropbox, redshift, volume) + status = fmt.Sprintf(" %s%s%s%s%s %s%s", + ramFree, weather, volIcon, volText, hTime, dropbox, rShift) ui.Dwm(status) // change this to the UI of choice } }