54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func Watch(ch <-chan *CompileReport, doneCh chan<- struct{}) {
|
|
defer close(doneCh)
|
|
|
|
times := map[*CompileConfig]time.Duration{}
|
|
|
|
states := map[*CompileConfig]CompileState{}
|
|
for _, cfg := range CompileConfigs {
|
|
states[cfg] = StateWaiting
|
|
}
|
|
|
|
cleared := false
|
|
|
|
for report := range ch {
|
|
states[report.Config] = report.State
|
|
times[report.Config] = report.Duration.Truncate(time.Second / 100)
|
|
if !*Silent {
|
|
PrintStates(states, times, cleared)
|
|
}
|
|
cleared = true
|
|
}
|
|
|
|
doneCh <- struct{}{}
|
|
}
|
|
|
|
func PrintStates(states map[*CompileConfig]CompileState, times map[*CompileConfig]time.Duration, 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
|
|
}
|
|
|
|
if state == StateDone {
|
|
fmt.Printf(fmt.Sprintf("%%-%ds %%s (%%s)\n", MaxConfigStringLength), cfg.String(), state, times[cfg])
|
|
} else {
|
|
fmt.Printf(fmt.Sprintf("%%-%ds %%s\n", MaxConfigStringLength), cfg.String(), state)
|
|
}
|
|
}
|
|
}
|