breto

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

commit b81caff39d1f8467ea203b80c9f9e392e3006ab2
parent 941d373a219bff196182aab3f327c096d008f2d9
Author: Jaron Swab <jrswab@tuta.io>
Date:   Sun, 12 Jan 2020 13:22:46 -0500

Merge pull request #9 from jrswab/feature/openmoji-integration

Emoji Integration
Diffstat:
MCHANGELOG.md | 8++++++++
MREADME.md | 34++++++++++------------------------
Micons/icons.go | 55+++++++++++++++++++++++++++++++++++++++++++++++--------
Micons/icons_test.go | 8++++----
Mmain.go | 19++++++++++---------
5 files changed, 79 insertions(+), 45 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.12.0] - January 12, 2020 + +### Added +- CLI flag to enable the use of emoji over Font Awesome for icon set + +### Changed +- README.md + ## [0.11.0] - January 11, 2020 ### Added diff --git a/README.md b/README.md @@ -11,57 +11,47 @@ Currently tested with DWM, i3wm, tmux, and Polybar. - Total disk space left in the binary's present partition. - Total battery percentage (off by default) - Icons -#### Current UIs: +- CLI flags for easier tweaking +#### Current UIs Tested: - DWM - i3wm - tmux - Polybar #### 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 +- `-dwm=true` to use in DWM's status bar +- `-emoji=true` to enable emoji icons instead of Font Awesome - `-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 +- `-volume=false` to remove volume percentage block ### Icons: #### To display icons in DWM. -1. Install Font Awesome 5 +1. Install Font Awesome 5 (or an emoji font) 2. Set FontAwesome as the second font in `dwm/config.h` - eg. `static const char *fonts[] = { "Source Code Pro:size=13", "Font Awesome 5 Free:style=Regular:size=14" };` + - if using an emoji font, replace the second font name with the emoji set 3. Relaunch DWM #### To display in tmux or i3wm: -1. Install Font Awesome 5 +1. Install Font Awesome 5 (or an emoji font) - Keep in mind that the icons are currently very small. - Research in progess. #### To display in Polybar: -1. Install Font Awesome 5: +1. Install Font Awesome 5 (or an emoji font) 2. Add to your Polybar config: + - If not using Font Awesome search for your emoji set with `fc-list` and replace "Font Awesome 5". ``` 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:  -- RAM:  -- Volume:     -- Syncthing:  -- Dropbox:  -- Redshift:  -- Battery:  - -Currently, the icons are much too small to be usefull in Tmux or i3wm without further configuration. -If you have an easy way to display FontAwesome icons at the same scale as the terminal text please submit a pull request. ## How To Use: 1. Open main.go in a text editor. @@ -102,9 +92,5 @@ tail = true - More information can be found at [wttr.in/:help](https://wttr.in/:help) 2. Add tweaks to `blocks/wttr.go` -## To-Do: -1. Scale icons in tmux and i3wm - - [This Unix Stack Exchange post may help](http://unix.stackexchange.com/questions/49779/ddg#49823) - ## License: MIT diff --git a/icons/icons.go b/icons/icons.go @@ -4,12 +4,24 @@ import ( "encoding/binary" "fmt" "os/exec" + "strconv" ) +func encodeEmoji(unicode string) string { + emoji, err := strconv.ParseInt(unicode, 16, 32) + if err != nil { + fmt.Println(err) + } + return fmt.Sprintf("%s ", string(emoji)) +} + // Dropbox sends the Dropbox icon when the app is running. -func Dropbox() (string, error) { +func Dropbox(emoji bool) (string, error) { // ps ux | awk '/dropbox/ {print $11}' | grep dropbox dbIcon := "" + if emoji { + dbIcon = encodeEmoji("00001F4E5") + } dbCmd := "ps ux | gawk '/dropbox/ {print $11}' | grep dropbox" runDbCmd, err := exec.Command("sh", "-c", dbCmd).Output() @@ -23,8 +35,11 @@ func Dropbox() (string, error) { } // Redshift sends the icon when the app is running. -func Redshift() (string, error) { +func Redshift(emoji bool) (string, error) { rsIcon := "" + if emoji { + rsIcon = encodeEmoji("00001F4A1") + } rsCmd := "ps ux | gawk '/redshift/ {print $11}' | grep redshift" runRsCmd, err := exec.Command("sh", "-c", rsCmd).Output() @@ -38,8 +53,11 @@ func Redshift() (string, error) { } // Syncthing sends the icon when the app is running. -func Syncthing() (string, error) { +func Syncthing(emoji bool) (string, error) { syncIcon := "" + if emoji { + syncIcon = encodeEmoji("00000FE0F") + } syncCmd := "ps ux | gawk '/syncthing/ {print $11}' | grep syncthing" runSyncCmd, err := exec.Command("sh", "-c", syncCmd).Output() @@ -53,11 +71,20 @@ func Syncthing() (string, error) { } // Volume sends the icon when the app is running. -func Volume() (string, error) { +func Volume(emoji bool) (string, error) { + // Font Awesome: volIconMute := " " volIconLow := " " volIconMid := " " volIconHigh := " " + + if emoji { + volIconMute = encodeEmoji("00001F507") + volIconLow = encodeEmoji("00001F508") + volIconMid = encodeEmoji("00001F509") + volIconHigh = encodeEmoji("00001F50A") + } + volCmd := "amixer -D pulse sget Master | awk '/Front Right:/ {print $5}' | grep -o '[0-9]*'" runVolCmd, err := exec.Command("sh", "-c", volCmd).Output() volValue := binary.LittleEndian.Uint16(runVolCmd) @@ -83,21 +110,33 @@ 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 { +func Dir(emoji bool) string { + if emoji { + return encodeEmoji("00001F4C2") + } return " " } // Mem sends the icon when the app is running. -func Mem() string { +func Mem(emoji bool) string { + if emoji { + return encodeEmoji("00001F4BE") + } return " " } // Temp sends the icon when the app is running. -func Temp() string { +func Temp(emoji bool) string { + if emoji { + return encodeEmoji("00001F321") + } return " " } // Power sends the icon when the app is running. -func Power() string { +func Power(emoji bool) string { + if emoji { + return encodeEmoji("000026A1") + } return " " } diff --git a/icons/icons_test.go b/icons/icons_test.go @@ -9,7 +9,7 @@ import ( // Any icon that simply displays no matter the status is now tested. func TestDropbox(t *testing.T) { - db, err := Dropbox() + db, err := Dropbox(false) if err != nil { t.Error(err) //.Error()) } @@ -17,7 +17,7 @@ func TestDropbox(t *testing.T) { } func TestRedshift(t *testing.T) { - rs, err := Redshift() + rs, err := Redshift(false) if err != nil { t.Error(err) } @@ -25,7 +25,7 @@ func TestRedshift(t *testing.T) { } func TestVolume(t *testing.T) { - vi, err := Volume() + vi, err := Volume(false) if err != nil { t.Error(err) } @@ -33,7 +33,7 @@ func TestVolume(t *testing.T) { } func TestSyncthing(t *testing.T) { - sync, err := Syncthing() + sync, err := Syncthing(false) if err != nil { t.Error(err) //.Error()) } diff --git a/main.go b/main.go @@ -13,7 +13,7 @@ import ( ) // CLI flag variables -var dwm, battery, clock, audio, memory, diskSpace, temperature, tray bool +var dwm, battery, clock, audio, memory, diskSpace, temperature, tray, emoji bool type info struct { hTime string @@ -51,6 +51,7 @@ 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") } func main() { @@ -107,32 +108,32 @@ 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(), stats.weather) + status = fmt.Sprintf("%s %s%s ", status, icons.Temp(emoji), stats.weather) } if diskSpace { - status = fmt.Sprintf("%s %s%s ", status, icons.Dir(), stats.homeSpace) + status = fmt.Sprintf("%s %s%s ", status, icons.Dir(emoji), stats.homeSpace) } if memory { - status = fmt.Sprintf("%s %s%s ", status, icons.Mem(), stats.ramFree) + status = fmt.Sprintf("%s %s%s ", status, icons.Mem(emoji), stats.ramFree) } if audio { stats.volText, _ = blocks.VolumeText() - ico.volIcon, _ = icons.Volume() + 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(), stats.power) + 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() - ico.dropbox, _ = icons.Dropbox() - ico.syncthing, _ = icons.Syncthing() + 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) }