breto

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

commit 6e2e1b290a6b56792e0f4d7449f50dd21ef9f980
parent 88ae205cb07cee5d31fb269732ebd97f702d68fb
Author: Jaron Swab <jrswab@tuta.io>
Date:   Wed,  8 Jan 2020 21:01:48 -0500

Merge pull request #7 from jrswab/develop

Added CLI Flags
Diffstat:
MCHANGELOG.md | 9+++++++++
MREADME.md | 55+++++++++++++++++++++++++++++++++++++++----------------
Mmain.go | 57++++++++++++++++++++++++++++++++++++---------------------
Mui/ui.go | 22++++++++++++++--------
4 files changed, 98 insertions(+), 45 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.10.0] - January 06, 2020 + +### Added +- CLI flag to enable DWM status bar out put `--dwm=true` to enable +- CLI flag to enable batter status information. + +### Changed +- `Status` formating for easier editing. + ## [0.9.1] - November 23, 2019 ### Added diff --git a/README.md b/README.md @@ -9,25 +9,41 @@ Currently tested with DWM, i3wm, and tmux. - Weather via wttr.in - Total RAM not used - Total disk space left in the binary's present partition. -- Total battery percentage (commented out by default) +- Total battery percentage (off by default) - Icons #### Current UIs: - DWM - i3wm - tmux +- Polybar + +#### CLI Flags +- `-dwm=true` to use in DWM's status bar +- `-battery=true` to enable battery block ### Icons: -To display icons in DWM. -1. Install FontAwesome v4 +#### To display icons in DWM. +1. Install Font Awesome 5 2. Set FontAwesome as the second font in `dwm/config.h` - - eg. `static const char *fonts[] = { "Source Code Pro:size=13", "FontAwesome:size=14" };` + - eg. `static const char *fonts[] = { "Source Code Pro:size=13", "Font Awesome 5 Free:style=Regular:size=14" };` 3. Relaunch DWM -To display in tmux or i3wm: -1. Install FontAwesome v4. +#### To display in tmux or i3wm: +1. Install Font Awesome 5 - Keep in mind that the icons are currently very small. - Research in progess. +#### To display in Polybar: +1. Install Font Awesome 5: +2. Add to your Polybar config: +``` +font-0 = {base font here} +font-1 = "Font Awesome 5 Free:style=Regular:pixelsize=12;1" +font-2 = "Font Awesome 5 Free:style=Solid:pixelsize=12;1" +font-3 = "Font Awesome 5 Brands:pixelsize=12;1" +``` +3. If not using Font Awesome 5 search for your version with `fc-list | grep Awesome`. + #### Current Icons: - Tempurature:  - Disk:  @@ -44,26 +60,34 @@ If you have an easy way to display FontAwesome icons at the same scale as the te ## How To Use: 1. Open main.go in a text editor. 2. Edit the last `status` variable to contain the blocks you wish to use. -3. Change the last line to match your UI (eg, `ui.Dwm(status)`). -4. Build the binary. -5. Edit your config file to use the new binary. +3. Build the binary. +4. Edit your config file to use the new binary. + - If using DWM execute with the `--dwm=true` flag. ### Adding to DWM: -- Simply set `ui.Dwm(status)`, compile, and execute. -- If you already have a startup script for DWM just add a new line for go-status +- If you already have a startup script for DWM just add a new line with the path to this binary. ### Addng to Tmux: - `set -g status-right "#($HOME/PATHTO/tmux-status)"` - If you have colors in this setting add the path at the end of the string - Be sure to use the correct path and name of the file you built with GO. - - Running `mv go-status ~/tmux-status` will allow you to use `"($HOME/tmux-status)"` in your config. + - Running `mv breto ~/tmux-status` will allow you to use `"($HOME/tmux-status)"` in your config. - `set -g status-right-length 53` - If you are not using all the custom packages this number can be lower - - This also will vary based on screen size. 53 is the minimum that worke for all current blocks + - This also will vary based on screen size. 53 is the minimum that worked for all current blocks on my montior. - If you notice the status getting cut off just increase the number and reload tmux. ### Adding to i3wm: -- In the i3wm confige file, change `status_command ...` to `status_command PATH/TO/go-status` +- In the i3wm confige file, change `status_command ...` to `status_command PATH/TO/breto` + +### Adding to Polybar: +- Add the following module to your Polybar configuration file: +``` +[module/breto] +type = custom/script +exec = /path/to/breto +tail = true +``` ## Wttr.in Options: 1. Add your area to the weather function @@ -73,8 +97,7 @@ If you have an easy way to display FontAwesome icons at the same scale as the te 2. Add tweaks to `blocks/wttr.go` ## To-Do: -1. Get a proper name -2. Scale icons in tmux and i3wm +1. Scale icons in tmux and i3wm - [This Unix Stack Exchange post may help](http://unix.stackexchange.com/questions/49779/ddg#49823) ## License: diff --git a/main.go b/main.go @@ -1,8 +1,10 @@ package main import ( + "flag" "fmt" "log" + "math" "time" "github.com/jrswab/breto/blocks" @@ -23,6 +25,7 @@ type info struct { ramFree string homeSpace string volText string + power string wttrErr error ramErr error homeErr error @@ -35,6 +38,7 @@ type symbols struct { dropbox string volIcon string syncthing string + bolt string } // batInfo holds information for battery capacity @@ -44,19 +48,23 @@ type batInfo struct { } 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{} - // Uncomment for battery status - /* - baty := batInfo{} - start := time.Now() - */ + 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 @@ -76,13 +84,12 @@ func main() { // add year & seconds with "Jan 02, 2006 15:04:05" stats.hTime = time.Now().Format("Jan 02 15:04") - // Uncomment for battery status - /* + if battery { baty.passed = time.Since(start).Seconds() - baty.fiveMins = math.Floor(math.Remainder(passed, 300)) - */ + baty.fiveMins = math.Floor(math.Remainder(baty.passed, 300)) + } - select { // update the go routine channels as they send data + select { // updates the go routine channels as they send data case stats.weather = <-cWttr: case stats.wttrErr = <-eWttr: log.Println(stats.wttrErr.Error()) @@ -102,19 +109,27 @@ func main() { ico.volIcon, _ = icons.Volume() ico.syncthing, _ = icons.Syncthing() - // Uncomment for battery status - /* - bolt = icons.Power() - if baty.fiveMins == 0 || passed < 10 { - battery, _ = blocks.Battery() + if battery { + if baty.fiveMins == 0 || baty.passed < 10 { + stats.power, _ = blocks.Battery() } - */ + } // Change by editing variables & `%s` - status = fmt.Sprintf(" %s%s %s%s %s%s %s%s %s %s%s%s", - 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 + 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) + } + status = fmt.Sprintf(" %s %s", status, stats.hTime) + status = fmt.Sprintf(" %s %s%s%s", status, ico.dropbox, ico.syncthing, ico.rShift) + + if dwm { + ui.Dwm(status) + } else { + ui.Default(status) + } } } diff --git a/ui/ui.go b/ui/ui.go @@ -5,7 +5,7 @@ import ( "os/exec" ) -// To have the status blocks appear in dwm we have to run xsetroot -name [status] +// Dwm - To have the status blocks appear in dwm we have to run xsetroot -name [status] // where [status] contains the data blocks func Dwm(status string) error { cmd := exec.Command("xsetroot", "-name", status) @@ -13,19 +13,25 @@ func Dwm(status string) error { return err } -// For tmux we only need to output the block to stdout +// Default is used when we only need to output the block to stdout. +// This is the default option. +// +// For tmux: // Add the following to your tmux config: // set -g status-right "#($HOME/PATHTO/go-status)" // where `go-status` is the compiled binary -func Tmux(status string) { - fmt.Println(status) -} - -// For i3wm we only need to output the block to stdout as we do with tmux. +// +// For i3wm: // Make sure to update the `bar {}` section in your i3wm // config file to the following: // status_command $HOME/PATH/TO/go-status // where `go-status` is the compiled binary -func I3wm(status string) { +// +// For Polybar: +// [module/breto] +// type = custom/script +// exec = /path/to/breto/binary +// tail = true +func Default(status string) { fmt.Println(status) }