breto

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

commit 941d373a219bff196182aab3f327c096d008f2d9
parent 6e2e1b290a6b56792e0f4d7449f50dd21ef9f980
Author: Jaron Swab <jrswab@tuta.io>
Date:   Sat, 11 Jan 2020 12:51:00 -0500

Merge pull request #8 from jrswab/develop

More CLI Flags
Diffstat:
M.gitignore | 2+-
MCHANGELOG.md | 15+++++++++++++++
MREADME.md | 8+++++++-
Mblocks/battery.go | 3++-
Mblocks/disk.go | 3++-
Mblocks/ram.go | 2+-
Mblocks/volume.go | 3++-
Mblocks/wttr.go | 2+-
Mmain.go | 97++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
9 files changed, 85 insertions(+), 50 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -8,7 +8,7 @@ *.dll *.so *.dylib -go-status +breto # Test binary, built with `go test -c` *.test diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.11.0] - January 11, 2020 + +### Added +- CLI flags for the clock, audio, memory, diskSpace, temperature, and tray +- `init()` to set up CLI flags instead. +- Comments for each exported block function +- Checks for CLI flags to disable go routines if the user disables a speific block + +### Changed +- `status` build to includ if statments based off CLI flag variables. +- CLI flag variables to be global after adding `init()` + +### Removed +- `|` from all block returns. + ## [0.10.0] - January 06, 2020 ### Added diff --git a/README.md b/README.md @@ -1,6 +1,6 @@ # Breto A status bar written in Go. -Currently tested with DWM, i3wm, and tmux. +Currently tested with DWM, i3wm, tmux, and Polybar. ## Current Features: ### Master Branch: @@ -20,6 +20,12 @@ Currently tested with DWM, i3wm, and tmux. #### CLI Flags - `-dwm=true` to use in DWM's status bar - `-battery=true` to enable battery block +- `-dateTime=false` to remove the date/time block +- `-volume=false` to remove volume percentage block +- `-ram=false` to remove RAM remaining block +- `-storage=false` to remove the home directory storage remaining block +- `-temp=false` to remove the weather block +- `-tray=false` to remove the "system" tray block ### Icons: #### To display icons in DWM. diff --git a/blocks/battery.go b/blocks/battery.go @@ -6,6 +6,7 @@ import ( "strings" ) +// Battery returns the current percentage remaining. func Battery() (string, error) { cmd := "cat /sys/class/power_supply/BAT0/capacity" runCmd, err := exec.Command("sh", "-c", cmd).Output() @@ -14,6 +15,6 @@ func Battery() (string, error) { } perc := "%" - level := fmt.Sprintf("%s%s |", strings.TrimSpace(string(runCmd)), perc) + level := fmt.Sprintf("%s%s", strings.TrimSpace(string(runCmd)), perc) return level, nil } diff --git a/blocks/disk.go b/blocks/disk.go @@ -8,6 +8,7 @@ import ( "time" ) +// HomeDisk returns the remaining home directory storage space in GiB func HomeDisk(cHomeDisk chan string, eHomeDisk chan error) { // df -h | awk '/home/ {print $4} var passed, hour float64 @@ -26,7 +27,7 @@ func HomeDisk(cHomeDisk chan string, eHomeDisk chan error) { eHomeDisk <- err } - homeFree = fmt.Sprintf("%s |", strings.TrimSpace(string(homeOut))) + homeFree = fmt.Sprintf("%s", strings.TrimSpace(string(homeOut))) cHomeDisk <- homeFree } } diff --git a/blocks/ram.go b/blocks/ram.go @@ -29,7 +29,7 @@ func FreeRam(cRam chan string, eRam chan error) { eRam <- err } - ramFree = fmt.Sprintf("%s |", + ramFree = fmt.Sprintf("%s", strings.TrimSpace(string(ramGib))) // set string cRam <- ramFree // send string diff --git a/blocks/volume.go b/blocks/volume.go @@ -6,6 +6,7 @@ import ( "strings" ) +// VolumeText sends back the current volume percent. 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() @@ -14,5 +15,5 @@ func VolumeText() (string, error) { } percent := "%" - return fmt.Sprintf("%s%s |", strings.TrimSpace(string(runVol)), percent), nil + return fmt.Sprintf("%s%s", strings.TrimSpace(string(runVol)), percent), nil } diff --git a/blocks/wttr.go b/blocks/wttr.go @@ -37,7 +37,7 @@ func Wttr(cWttr chan string, eWttr chan error) { // Several attempts to catch the exact error proved difficult // so now we catch the correct outupt instead. if strings.Contains(data, "+") || strings.Contains(data, "-") { - weather = fmt.Sprintf("%s |", strings.TrimSpace(data)) + weather = fmt.Sprintf("%s", strings.TrimSpace(data)) cWttr <- weather } else { eWttr <- fmt.Errorf("Expected temp, got: %s", data) diff --git a/main.go b/main.go @@ -12,13 +12,9 @@ import ( "github.com/jrswab/breto/ui" ) -// To Add Battery Status: -// Uncomment all lines that follow the message: -// "Uncomment for battery status" -// Also, add the correct string formatting to -// the status assignment at the end of the file and add "math" to the imports +// CLI flag variables +var dwm, battery, clock, audio, memory, diskSpace, temperature, tray bool -// info holds dynamic information type info struct { hTime string weather string @@ -31,7 +27,6 @@ type info struct { homeErr error } -// icons holds the text of dynamic icons type symbols struct { status string rShift string @@ -41,44 +36,51 @@ type symbols struct { bolt string } -// batInfo holds information for battery capacity type batInfo struct { passed float64 fiveMins float64 } +func init() { + // Setup and define cli flags + flag.BoolVar(&dwm, "dwm", false, "Used to enable output for DWM's status bar.\n Example: --dwm=true") + flag.BoolVar(&battery, "battery", false, "Used to enable battery module.\n Example: --battery=true") + flag.BoolVar(&clock, "dateTime", true, "Used to disable the date and time module.\n Example: --dateTime=false") + flag.BoolVar(&audio, "volume", true, "Used to disable the volume module.\n Example: --volume=false") + flag.BoolVar(&memory, "ram", true, "Used to disable the RAM module.\n Example: --ram=false") + flag.BoolVar(&diskSpace, "storage", true, "Used to disable the home directory storage module.\n Example: --storage=false") + flag.BoolVar(&temperature, "temp", true, "Used to disable the temperature module.\n Example: --temp=false") + flag.BoolVar(&tray, "tray", true, "Used to disable the custom tray module.\n Example: --tray=false") +} + func main() { - var dwm bool - flag.BoolVar(&dwm, "dwm", false, "Used to enable output for DWM's status bar\n Example: -dwm=true") - var battery bool - flag.BoolVar(&battery, "battery", false, "Used to enable battery module.\n Example: -battery=true") flag.Parse() - var status string stats := info{} ico := symbols{} baty := batInfo{} - start := time.Now() - - // These are static icons and only need defined at the start - homeDir := icons.Dir() - memIco := icons.Mem() - tempIco := icons.Temp() - ico.bolt = icons.Power() // Each Go routine has it's own timer to delay the execution of the command. - cWttr := make(chan string) // start weather data routine + // A Go routine will run unless it's CLI flag is set to false. + cWttr := make(chan string) eWttr := make(chan error) - go blocks.Wttr(cWttr, eWttr) + if temperature { + go blocks.Wttr(cWttr, eWttr) + } - cRAM := make(chan string) // start free ram data routine + cRAM := make(chan string) eRAM := make(chan error) - go blocks.FreeRam(cRAM, eRAM) + if memory { + go blocks.FreeRam(cRAM, eRAM) + } - cHomeDisk := make(chan string) // start free home dir space routine + cHomeDisk := make(chan string) eHomeDisk := make(chan error) - go blocks.HomeDisk(cHomeDisk, eHomeDisk) + if diskSpace { + go blocks.HomeDisk(cHomeDisk, eHomeDisk) + } + start := time.Now() // for batter time math ticker := time.NewTicker(time.Second) for range ticker.C { // add year & seconds with "Jan 02, 2006 15:04:05" @@ -102,30 +104,39 @@ func main() { default: } - // Assign Icons & non Go Routine blocks every round - ico.rShift, _ = icons.Redshift() - ico.dropbox, _ = icons.Dropbox() - stats.volText, _ = blocks.VolumeText() - ico.volIcon, _ = icons.Volume() - ico.syncthing, _ = icons.Syncthing() - + // 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(), stats.weather) + } + if diskSpace { + status = fmt.Sprintf("%s %s%s ", status, icons.Dir(), stats.homeSpace) + } + if memory { + status = fmt.Sprintf("%s %s%s ", status, icons.Mem(), stats.ramFree) + } + if audio { + stats.volText, _ = blocks.VolumeText() + ico.volIcon, _ = icons.Volume() + 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(), stats.power) } - - // Change by editing variables & `%s` - status = fmt.Sprintf("%s%s", tempIco, stats.weather) - status = fmt.Sprintf(" %s %s%s", status, homeDir, stats.homeSpace) - status = fmt.Sprintf(" %s %s%s", status, memIco, stats.ramFree) - status = fmt.Sprintf(" %s %s%s", status, ico.volIcon, stats.volText) - if battery { - status = fmt.Sprintf(" %s %s%s", status, ico.bolt, stats.power) + if clock { + status = fmt.Sprintf("%s %s ", status, stats.hTime) + } + if tray { + ico.rShift, _ = icons.Redshift() + ico.dropbox, _ = icons.Dropbox() + ico.syncthing, _ = icons.Syncthing() + status = fmt.Sprintf("%s %s%s%s", status, ico.dropbox, ico.syncthing, ico.rShift) } - status = fmt.Sprintf(" %s %s", status, stats.hTime) - status = fmt.Sprintf(" %s %s%s%s", status, ico.dropbox, ico.syncthing, ico.rShift) + // Output methods as specified by CLI flags. if dwm { ui.Dwm(status) } else {