summaryrefslogtreecommitdiff
path: root/status/00-status.go
diff options
context:
space:
mode:
Diffstat (limited to 'status/00-status.go')
-rw-r--r--status/00-status.go49
1 files changed, 24 insertions, 25 deletions
diff --git a/status/00-status.go b/status/00-status.go
index 3543d0b..ec2a069 100644
--- a/status/00-status.go
+++ b/status/00-status.go
@@ -3,7 +3,6 @@ package status // import "hhvn.uk/hbspbar/status"
import (
"fmt"
"time"
- "sync"
"image"
"image/color"
@@ -12,32 +11,38 @@ import (
"hhvn.uk/hbspbar/common"
)
-var Status map[int]*status
-var Mutex sync.Mutex
-var statusid map[string]int
-var Updated chan bool
-var updates chan *status
+var NewBlocks = make(chan *Blocks)
+var updates = make(chan *status)
+var statusid = make(map[string]int)
-const (
-)
+type Blocks map[int]*status
+
+func (b *Blocks) Len() int {
+ return len(map[int]*status(*b))
+}
+
+func (b *Blocks) Get(i int) (s *status, ok bool) {
+ s, ok = (map[int]*status(*b))[i]
+ return
+}
+
+type status struct {
+ Name string
+ I *image.RGBA
+ W int
+}
func init() {
- Status = make(map[int]*status)
- statusid = make(map[string]int)
- Updated = make(chan bool)
- updates = make(chan *status)
+ status := make(map[int]*status)
go func() {
- for {
- s := <- updates
-
+ for s := range updates {
id := statusid[s.Name]
- Mutex.Lock()
- Status[id] = s
- Mutex.Unlock()
+ status[id] = s
- Updated <- true
+ b := Blocks(status)
+ NewBlocks <- &b
}
}()
}
@@ -52,12 +57,6 @@ func register(name string) {
statusid[name] = nid
}
-type status struct {
- Name string
- I *image.RGBA
- W int
-}
-
func newUpdate(name string) (*status) {
var s status