breto

A status bar written in Go.
git clone git://git.swab.dev/breto.git
Log | Files | Refs | README | LICENSE

commit 866e9dcd95abc5e88806c97fb6e561726ebbcbb6
parent 3122afe88be3e24fb39c3fb9a9477245d5d43b1e
Author: Jaron Swab <jaron@swab.dev>
Date:   Wed,  7 Apr 2021 21:10:28 -0400

Started refactor

Diffstat:
MCHANGELOG.md | 5+++++
Micons/icons.go | 7+++++++
Mmain.go | 66++++++++++++++++++++++++------------------------------------------
Astats/stats.go | 14++++++++++++++
4 files changed, 50 insertions(+), 42 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -5,6 +5,11 @@ 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] +### Changed +- switch from github to repo for imports + +### Added +- stats package for info struct ## [0.12.0] - January 12, 2020 diff --git a/icons/icons.go b/icons/icons.go @@ -6,6 +6,13 @@ import ( "strconv" ) +type Symbols struct { + RShift string + Dropbox string + VolIcon string + Syncthing string +} + func encodeEmoji(unicode string) string { emoji, err := strconv.ParseInt(unicode, 16, 32) if err != nil { diff --git a/main.go b/main.go @@ -7,40 +7,15 @@ import ( "math" "time" - "github.com/jrswab/breto/blocks" - "github.com/jrswab/breto/icons" - "github.com/jrswab/breto/ui" + "git.swab.dev/breto/blocks" + "git.swab.dev/breto/icons" + "git.swab.dev/breto/stats" + "git.swab.dev/breto/ui" ) // CLI flag variables var dwm, battery, clock, audio, memory, diskSpace, temperature, tray, emoji bool -type info struct { - hTime string - weather string - ramFree string - homeSpace string - volText string - power string - wttrErr error - ramErr error - homeErr error -} - -type symbols struct { - status string - rShift string - dropbox string - volIcon string - syncthing string - bolt string -} - -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") @@ -51,10 +26,10 @@ func init() { 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") - flag.BoolVar(&emoji, "emoji", false, "Used to enable Openmoji icons instead of Awosome Font.\n Example: --emoji=true") + flag.BoolVar(&emoji, "emoji", false, "Used to enable Openmoji icons instead of Awesome Font.\n Example: --emoji=true") } -func formatOutput(status string, stats info, ico symbols, baty batInfo) string { +func formatOutput(status string, stats *stats.Info, ico *icons.Symbols, baty batInfo) string { if temperature { status = fmt.Sprintf("%s %s%s ", status, icons.Temp(emoji), stats.weather) } @@ -87,29 +62,36 @@ func formatOutput(status string, stats info, ico symbols, baty batInfo) string { return status } +type batInfo struct { + passed float64 + fiveMins float64 +} + func main() { flag.Parse() - stats := info{} - ico := symbols{} - baty := batInfo{} + var ( + stats = new(stats.Info) + ico = new(icons.Symbols) + baty = batInfo{} + cWttr = make(chan string) + eWttr = make(chan error) + cRAM = make(chan string) + eRAM = make(chan error) + cHomeDisk = make(chan string) + eHomeDisk = make(chan error) + ) // Each Go routine has it's own timer to delay the execution of the command. // A Go routine will run unless it's CLI flag is set to false. - cWttr := make(chan string) - eWttr := make(chan error) if temperature { go blocks.Wttr(cWttr, eWttr) } - cRAM := make(chan string) - eRAM := make(chan error) if memory { go blocks.FreeRam(cRAM, eRAM) } - cHomeDisk := make(chan string) - eHomeDisk := make(chan error) if diskSpace { go blocks.HomeDisk(cHomeDisk, eHomeDisk) } @@ -139,8 +121,8 @@ func main() { } // Status bar information as defined by the CLI flags. - status := "" // reset status on every run. - finalStatus := formatOutput(status, stats, ico, baty) + // reset status on every run. + finalStatus := formatOutput("", stats, ico, baty) // Output methods as specified by CLI flags. if dwm { diff --git a/stats/stats.go b/stats/stats.go @@ -0,0 +1,14 @@ +package stats + +type Info struct { + HTime string + Weather string + RamFree string + HomeSpace string + VolText string + Power string + + WttrErr error + RamErr error + HomeErr error +}