Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Clean up widget initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Apr 13, 2018
1 parent 2d86953 commit d6ffbec
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/signal"
"strconv"
"sync"
"syscall"
"time"

Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit d6ffbec

Please sign in to comment.