forked from davidscholberg/goblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goblocks.go
72 lines (64 loc) · 1.41 KB
/
goblocks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"log"
"os"
"reflect"
"github.com/davidscholberg/go-i3barjson"
"github.com/davidscholberg/goblocks/lib/modules"
)
func main() {
errLogger := log.New(os.Stderr, "error: ", 0)
gb, err := modules.NewGoblocks()
if err != nil {
errLogger.Fatalln(err)
}
h := i3barjson.Header{Version: 1}
err = i3barjson.Init(os.Stdout, nil, h, gb.Cfg.Global.Debug)
if err != nil {
errLogger.Fatalln(err)
}
// send the first statusLine
err = i3barjson.Update(gb.StatusLine)
if err != nil {
errLogger.Fatalln(err)
}
shouldRefresh := false
for {
// select on all chans
i, _, _ := reflect.Select(gb.SelectCases.Cases)
selectReturn := gb.SelectCases.Actions[i](gb.SelectCases.Blocks[i])
if selectReturn.Exit {
fmt.Println("")
break
}
if selectReturn.SignalRefresh {
shouldRefresh = true
} else if selectReturn.Refresh {
if shouldRefresh {
err = i3barjson.Update(gb.StatusLine)
if err != nil {
errLogger.Fatalln(err)
}
shouldRefresh = false
}
} else if selectReturn.ForceRefresh {
err = i3barjson.Update(gb.StatusLine)
if err != nil {
errLogger.Fatalln(err)
}
shouldRefresh = false
} else if selectReturn.Reload {
gb.Reset()
gb, err = modules.NewGoblocks()
if err != nil {
errLogger.Fatalln(err)
}
err = i3barjson.Update(gb.StatusLine)
if err != nil {
errLogger.Fatalln(err)
}
shouldRefresh = false
}
}
}