breto

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

commit ec6d3700ec545428e41b9e3e77daae4fb8237673
parent 6e2f521e99196f918a6efabaf6c8d2dda00ce562
Author: Jaron Swab <jrswab@tuta.io>
Date:   Thu, 10 Oct 2019 20:24:05 -0400

Merge pull request #5 from jrswab/develop

Added Structs
Diffstat:
MCHANGELOG.md | 4++++
Ago.mod | 3+++
Micons/icons.go | 9+++++++++
Mmain.go | 93+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
4 files changed, 76 insertions(+), 33 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -5,14 +5,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.9.0] - October 10, 2019 ### Added - In code instructions to enable battery status. - Icons package for clearer code. +- Descriptions to `icons.go` ### Changed - Commented out all battery status code in main.go - wttr custom error message to used fmt.Errorf instead for errors.New - Icons from calls like `blocks.VolumeIcon()` to calls like `icons.Volume()`. +- Information data from variables in main.go to structs ### Removed - The errors package from wttr.go diff --git a/go.mod b/go.mod @@ -0,0 +1,3 @@ +module github.com/jrswab/breto + +go 1.12 diff --git a/icons/icons.go b/icons/icons.go @@ -6,6 +6,7 @@ import ( "os/exec" ) +// Dropbox sends the Dropbox icon when the app is running. func Dropbox() (string, error) { // ps ux | awk '/dropbox/ {print $11}' | grep dropbox dbIcon := "" @@ -21,6 +22,7 @@ func Dropbox() (string, error) { return "", nil } +// Redshift sends the icon when the app is running. func Redshift() (string, error) { rsIcon := "" rsCmd := "ps ux | gawk '/redshift/ {print $11}' | grep redshift" @@ -35,6 +37,7 @@ func Redshift() (string, error) { return "", nil } +// Syncthing sends the icon when the app is running. func Syncthing() (string, error) { syncIcon := "" syncCmd := "ps ux | gawk '/syncthing/ {print $11}' | grep syncthing" @@ -49,6 +52,7 @@ func Syncthing() (string, error) { return "", nil } +// Volume sends the icon when the app is running. func Volume() (string, error) { volIconMute := " " volIconLow := " " @@ -77,18 +81,23 @@ func Volume() (string, error) { } // The following have no checks that need to be made + +// Dir sends the icon when the app is running. func Dir() string { return " " } +// Mem sends the icon when the app is running. func Mem() string { return " " } +// Temp sends the icon when the app is running. func Temp() string { return " " } +// Power sends the icon when the app is running. func Power() string { return " " } diff --git a/main.go b/main.go @@ -2,11 +2,12 @@ package main import ( "fmt" - "github.com/jrswab/go-status/blocks" - "github.com/jrswab/go-status/icons" - "github.com/jrswab/go-status/ui" "log" "time" + + "github.com/jrswab/breto/blocks" + "github.com/jrswab/breto/icons" + "github.com/jrswab/breto/ui" ) // To Add Battery Status: @@ -15,15 +16,40 @@ import ( // Also, add the correct string formatting to // the status assignment at the end of the file and add "math" to the imports -func main() { - var weather, ramFree, homeSpace string // Go routine blocks - var wttrErr, ramErr, homeErr error // Go routine errors - var status, hTime, rShift, dropbox, volIcon, volText, syncthing string +// info holds dynamic information +type info struct { + hTime string + weather string + ramFree string + homeSpace string + volText string + wttrErr error + ramErr error + homeErr error +} + +// icons holds the text of dynamic icons +type symbols struct { + status string + rShift string + dropbox string + volIcon string + syncthing string +} + +// batInfo holds information for battery capacity +type batInfo struct { + passed float64 + fiveMins float64 +} +func main() { + var status string + stats := info{} + ico := symbols{} // Uncomment for battery status /* - var bolt, battery string - var passed, fiveMins float64 + baty := batInfo{} start := time.Now() */ @@ -37,9 +63,9 @@ func main() { eWttr := make(chan error) go blocks.Wttr(cWttr, eWttr) - cRam := make(chan string) // start free ram data routine - eRam := make(chan error) - go blocks.FreeRam(cRam, eRam) + cRAM := make(chan string) // start free ram data routine + eRAM := make(chan error) + go blocks.FreeRam(cRAM, eRAM) cHomeDisk := make(chan string) // start free home dir space routine eHomeDisk := make(chan error) @@ -48,46 +74,47 @@ func main() { ticker := time.NewTicker(time.Second) for range ticker.C { // add year & seconds with "Jan 02, 2006 15:04:05" - hTime = time.Now().Format("Jan 02 15:04") + stats.hTime = time.Now().Format("Jan 02 15:04") // Uncomment for battery status /* - passed = time.Since(start).Seconds() - fiveMins = math.Floor(math.Remainder(passed, 300)) + baty.passed = time.Since(start).Seconds() + baty.fiveMins = math.Floor(math.Remainder(passed, 300)) */ select { // update the go routine channels as they send data - case weather = <-cWttr: - case wttrErr = <-eWttr: - log.Println(wttrErr.Error()) - case ramFree = <-cRam: - case ramErr = <-eRam: - log.Println(ramErr.Error()) - case homeSpace = <-cHomeDisk: - case homeErr = <-eHomeDisk: - log.Println(homeErr.Error()) + case stats.weather = <-cWttr: + case stats.wttrErr = <-eWttr: + log.Println(stats.wttrErr.Error()) + case stats.ramFree = <-cRAM: + case stats.ramErr = <-eRAM: + log.Println(stats.ramErr.Error()) + case stats.homeSpace = <-cHomeDisk: + case stats.homeErr = <-eHomeDisk: + log.Println(stats.homeErr.Error()) default: } // Assign Icons & non Go Routine blocks every round - rShift, _ = icons.Redshift() - dropbox, _ = icons.Dropbox() - volText, _ = blocks.VolumeText() - volIcon, _ = icons.Volume() - syncthing, _ = icons.Syncthing() + ico.rShift, _ = icons.Redshift() + ico.dropbox, _ = icons.Dropbox() + stats.volText, _ = blocks.VolumeText() + ico.volIcon, _ = icons.Volume() + ico.syncthing, _ = icons.Syncthing() // Uncomment for battery status /* bolt = icons.Power() - if fiveMins == 0 || passed < 10 { + if baty.fiveMins == 0 || passed < 10 { battery, _ = blocks.Battery() } */ // Change by editing variables & `%s` status = fmt.Sprintf(" %s%s %s%s %s%s %s%s %s %s%s%s", - tempIco, weather, homeDir, homeSpace, memIco, ramFree, volIcon, volText, - hTime, dropbox, syncthing, rShift) - ui.Dwm(status) // change this to the UI of choice + tempIco, stats.weather, homeDir, stats.homeSpace, + memIco, stats.ramFree, ico.volIcon, stats.volText, + stats.hTime, ico.dropbox, ico.syncthing, ico.rShift) + ui.Tmux(status) // change this to the UI of choice } }