diff options
| author | hhvn <dev@hhvn.uk> | 2023-11-19 14:50:06 +0000 |
|---|---|---|
| committer | hhvn <dev@hhvn.uk> | 2023-11-19 14:50:06 +0000 |
| commit | f5e80f5bdcf43b7974064168c3eb0d4e993528df (patch) | |
| tree | ba3a5214c954ff842f6cce64076c4eabcfa9faf2 /status | |
| parent | 4722a069233b35efd0b600c973e7a7e9bca01d16 (diff) | |
Create function for drawing percentage usage bars
Diffstat (limited to 'status')
| -rw-r--r-- | status/00-status.go | 17 | ||||
| -rw-r--r-- | status/02-cpu.go | 12 |
2 files changed, 18 insertions, 11 deletions
diff --git a/status/00-status.go b/status/00-status.go index 809297b..6fcaf33 100644 --- 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 index 34379fb..e00d74f 100644 --- 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 |