breto

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

commit 3122afe88be3e24fb39c3fb9a9477245d5d43b1e
parent c5c4e0a3077a071d68cbe65450bd2c750773a82a
Author: Jaron Swab <jrswab@tuta.io>
Date:   Mon, 16 Mar 2020 22:08:29 -0400

Fixed volume icon data issue

Also moved the string creation into it's own function.

Diffstat:
MREADME.md | 2+-
Micons/icons.go | 10++++++----
Mmain.go | 67++++++++++++++++++++++++++++++++++++-------------------------------
3 files changed, 43 insertions(+), 36 deletions(-)

diff --git a/README.md b/README.md @@ -10,9 +10,9 @@ Currently tested with DWM, i3wm, tmux, and Polybar. - Weather via wttr.in - Total RAM not used - Total disk space left in the binary's present partition. +- Audio volume percentage (pamixer needs installed) - Total battery percentage (off by default) - Icons -- CLI flags for easier tweaking #### Current UIs Tested: - DWM - i3wm diff --git a/icons/icons.go b/icons/icons.go @@ -1,7 +1,6 @@ package icons import ( - "encoding/binary" "fmt" "os/exec" "strconv" @@ -85,14 +84,17 @@ func Volume(emoji bool) (string, error) { volIconHigh = encodeEmoji("00001F50A") } - volCmd := "amixer -D pulse sget Master | awk '/Front Right:/ {print $5}' | grep -o '[0-9]*'" + volCmd := "pamixer --get-volume | tr -d '\n'" runVolCmd, err := exec.Command("sh", "-c", volCmd).Output() - volValue := binary.LittleEndian.Uint16(runVolCmd) - if err != nil && err.Error() != "exit status 1" { return "", err } + volValue, err := strconv.Atoi(string(runVolCmd)) + if err != nil { + return "", err + } + switch { case volValue == 0: return fmt.Sprintf("%s", volIconMute), nil diff --git a/main.go b/main.go @@ -54,6 +54,39 @@ func init() { flag.BoolVar(&emoji, "emoji", false, "Used to enable Openmoji icons instead of Awosome Font.\n Example: --emoji=true") } +func formatOutput(status string, stats info, ico symbols, baty batInfo) string { + if temperature { + status = fmt.Sprintf("%s %s%s ", status, icons.Temp(emoji), stats.weather) + } + if diskSpace { + status = fmt.Sprintf("%s %s%s ", status, icons.Dir(emoji), stats.homeSpace) + } + if memory { + status = fmt.Sprintf("%s %s%s ", status, icons.Mem(emoji), stats.ramFree) + } + if audio { + stats.volText, _ = blocks.VolumeText() + ico.volIcon, _ = icons.Volume(emoji) + status = fmt.Sprintf("%s %s%s ", status, ico.volIcon, stats.volText) + } + if battery { + if baty.fiveMins == 0 || baty.passed < 10 { + stats.power, _ = blocks.Battery() + } + status = fmt.Sprintf("%s %s%s ", status, icons.Power(emoji), stats.power) + } + if clock { + status = fmt.Sprintf("%s %s ", status, stats.hTime) + } + if tray { + ico.rShift, _ = icons.Redshift(emoji) + ico.dropbox, _ = icons.Dropbox(emoji) + ico.syncthing, _ = icons.Syncthing(emoji) + status = fmt.Sprintf("%s %s%s%s", status, ico.dropbox, ico.syncthing, ico.rShift) + } + return status +} + func main() { flag.Parse() @@ -107,41 +140,13 @@ func main() { // Status bar information as defined by the CLI flags. status := "" // reset status on every run. - if temperature { - status = fmt.Sprintf("%s %s%s ", status, icons.Temp(emoji), stats.weather) - } - if diskSpace { - status = fmt.Sprintf("%s %s%s ", status, icons.Dir(emoji), stats.homeSpace) - } - if memory { - status = fmt.Sprintf("%s %s%s ", status, icons.Mem(emoji), stats.ramFree) - } - if audio { - stats.volText, _ = blocks.VolumeText() - ico.volIcon, _ = icons.Volume(emoji) - status = fmt.Sprintf("%s %s%s ", status, ico.volIcon, stats.volText) - } - if battery { - if baty.fiveMins == 0 || baty.passed < 10 { - stats.power, _ = blocks.Battery() - } - status = fmt.Sprintf("%s %s%s ", status, icons.Power(emoji), stats.power) - } - if clock { - status = fmt.Sprintf("%s %s ", status, stats.hTime) - } - if tray { - ico.rShift, _ = icons.Redshift(emoji) - ico.dropbox, _ = icons.Dropbox(emoji) - ico.syncthing, _ = icons.Syncthing(emoji) - status = fmt.Sprintf("%s %s%s%s", status, ico.dropbox, ico.syncthing, ico.rShift) - } + finalStatus := formatOutput(status, stats, ico, baty) // Output methods as specified by CLI flags. if dwm { - ui.Dwm(status) + ui.Dwm(finalStatus) } else { - ui.Default(status) + ui.Default(finalStatus) } } }