hbspbar

[WIP] bspwm status bar
git clone https://hhvn.uk/hbspbar
git clone git://hhvn.uk/hbspbar
Log | Files | Refs

commit f5e80f5bdcf43b7974064168c3eb0d4e993528df
parent 4722a069233b35efd0b600c973e7a7e9bca01d16
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 19 Nov 2023 14:50:06 +0000

Create function for drawing percentage usage bars

Diffstat:
Mstatus/00-status.go | 17+++++++++++++++++
Mstatus/02-cpu.go | 12+-----------
2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/status/00-status.go b/status/00-status.go @@ -91,6 +91,10 @@ func blendGYR(percent int) color.Color { return drw.Blend3(config.Green, config.Yellow, config.Red, percent) } +func blendBg(c color.Color) color.Color { + return drw.Blend(c, config.Status, 75) +} + func (s *status) furthest(x int) { if x > s.W { s.W = x @@ -107,3 +111,16 @@ func (s *status) drawRect(x, y, w, h int, c color.Color, fill bool) { drw.DrawRect(s.I, x, y, w, h, c, fill) s.furthest(x + w) } + +func (s *status) drawPercentBar(x, percent int) int { + tbpad := 3 + th := int(config.H) - tbpad * 2 + 1 + h := int(th * percent / 100) + fg := blendGYR(percent) + bg := blendBg(fg) + + s.drawRect(x, tbpad - 1, 3, th, bg, true) + s.drawRect(x, tbpad + th - h - 1, 3, h, fg, true) + + return 5 +} diff --git a/status/02-cpu.go b/status/02-cpu.go @@ -5,8 +5,6 @@ import ( "errors" "strings" - "hhvn.uk/hbspbar/drw" - "hhvn.uk/hbspbar/config" "hhvn.uk/hbspbar/common" ) @@ -104,15 +102,7 @@ func cpu(name string) error { ltotal = ltotal - total[i] used := int((100 * (ltotal - lidle)) / ltotal) - tbpad := 3 - th := int(config.H) - tbpad * 2 + 1 - h := int(th * used / 100) - fg := blendGYR(used) - bg := drw.Blend(fg, config.Status, 75) - - u.drawRect(cx, tbpad - 1, 3, th, bg, true) - u.drawRect(cx, tbpad + th - h - 1, 3, h, fg, true) - cx += 5 + cx += u.drawPercentBar(cx, used) } temps := 0