summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-04-13 08:54:20 -0700
committerCaleb Bassi <calebjbassi@gmail.com>2018-04-13 08:54:20 -0700
commitd6ffbec35bed4b4a48d4c8613949dcc623b5bf7a (patch)
tree4a58d4b5542e5b0b1da2f89c96e29e35fd9dfe97
parent2d86953e621ad2487ab78b06727622d2fb86f48f (diff)
Clean up widget initialization
-rw-r--r--main.go38
1 files changed, 22 insertions, 16 deletions
diff --git a/main.go b/main.go
index 3fb95c6..6d7799d 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ import (
"os"
"os/signal"
"strconv"
+ "sync"
"syscall"
"time"
@@ -24,6 +25,7 @@ var (
// proc widget takes longer to load, wait to render until it loads data
widgetsLoaded = make(chan bool, 1)
+ wg sync.WaitGroup
// used to render the proc widget whenever a key is pressed for it
keyPressed = make(chan bool, 1)
// used to render cpu and mem when zoom has changed
@@ -189,44 +191,48 @@ func widgetColors() {
}
}
-func main() {
- cliArguments()
-
- keyBinds()
-
- // need to do this before initializing widgets so that they can inherit the colors
- termuiColors()
+func initWidgets() {
+ wg.Add(widgetCount)
go func() {
+ defer wg.Done()
cpu = w.NewCPU(interval, zoom)
- widgetsLoaded <- true
}()
go func() {
+ defer wg.Done()
mem = w.NewMem(interval, zoom)
- widgetsLoaded <- true
}()
go func() {
+ defer wg.Done()
proc = w.NewProc(keyPressed)
- widgetsLoaded <- true
}()
if !minimal {
go func() {
+ defer wg.Done()
net = w.NewNet()
- widgetsLoaded <- true
}()
go func() {
+ defer wg.Done()
disk = w.NewDisk()
- widgetsLoaded <- true
}()
go func() {
+ defer wg.Done()
temp = w.NewTemp()
- widgetsLoaded <- true
}()
}
- for i := 0; i < widgetCount; i++ {
- <-widgetsLoaded
- }
+ wg.Wait()
+}
+
+func main() {
+ cliArguments()
+
+ keyBinds()
+
+ // need to do this before initializing widgets so that they can inherit the colors
+ termuiColors()
+
+ initWidgets()
widgetColors()