hbspbar

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

commit 4e7b725a88ed1ad19cc67cbbbb46f3702c3bee97
parent e6a5202d0c75bc2ee744a76b73147726e91ee732
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 27 Jan 2024 16:53:24 +0000

register() in statuses: handle errs and start goroutine

Diffstat:
Mstatus/00-status.go | 30+++++++++++++++++-------------
Mstatus/01-bat.go | 9+--------
Mstatus/02-cpu.go | 9+--------
Mstatus/03-mem.go | 9+--------
4 files changed, 20 insertions(+), 37 deletions(-)

diff --git a/status/00-status.go b/status/00-status.go @@ -47,7 +47,7 @@ func init() { }() } -func register(name string) { +func register(name string, fn func(string) error) { nid := 0 for _, id := range statusid { if id >= nid { @@ -55,6 +55,22 @@ func register(name string) { } } statusid[name] = nid + + go func(){ + for { + err := fn(name) + + if err != nil { + common.Error("status \"%s\": %s\n", name, err) + + u := newUpdate(name) + u.drawText(0, config.Red, fmt.Sprintf("[err: %s]", name)) + updates <- u + + sleep(5) + } + } + }() } func newUpdate(name string) (*status) { @@ -70,18 +86,6 @@ func newUpdate(name string) (*status) { return &s } -func checkError(name string, err error) { - if err == nil { return } - - common.Error("status \"%s\": %s\n", name, err) - - u := newUpdate(name) - u.drawText(0, config.Red, fmt.Sprintf("[err: %s]", name)) - updates <- u - - sleep(5) -} - func sleep(s int) { time.Sleep(time.Duration(s) * time.Second) } diff --git a/status/01-bat.go b/status/01-bat.go @@ -94,12 +94,5 @@ func bat(name string) error { } func init() { - name := "bat" - register(name) - - go func(){ - for { - checkError(name, bat(name)) - } - }() + register("bat", bat) } diff --git a/status/02-cpu.go b/status/02-cpu.go @@ -132,12 +132,5 @@ func cpu(name string) error { } func init() { - name := "cpu" - register(name) - - go func(){ - for { - checkError(name, cpu(name)) - } - }() + register("cpu", cpu) } diff --git a/status/03-mem.go b/status/03-mem.go @@ -52,12 +52,5 @@ func mem(name string) error { } func init() { - name := "mem" - register(name) - - go func() { - for { - checkError(name, mem(name)) - } - }() + register("mem", mem) }