gocc/watch.go
2022-08-17 19:37:46 +02:00

44 lines
772 B
Go

package main
import "fmt"
func Watch(ch <-chan *CompileReport, doneCh chan<- struct{}) {
defer close(doneCh)
states := map[*CompileConfig]CompileState{}
for _, cfg := range CompileConfigs {
states[cfg] = StateWaiting
}
cleared := false
for report := range ch {
states[report.Config] = report.State
if !*Silent {
PrintStates(states, cleared)
}
cleared = true
}
doneCh <- struct{}{}
}
func PrintStates(states map[*CompileConfig]CompileState, clear bool) {
if clear {
for i := 0; i < len(CompileConfigs); i++ {
goUp()
clearEOL()
}
}
for _, cfg := range CompileConfigs {
state, ok := states[cfg]
if !ok {
fmt.Println()
continue
}
fmt.Printf(fmt.Sprintf("%%-%ds %%s\n", MaxConfigStringLength), cfg.String(), state)
}
}