gocc/compile_report.go
2022-08-17 23:38:41 +02:00

55 lines
1.2 KiB
Go

package main
import (
"time"
"github.com/fatih/color"
)
type CompileReport struct {
Config *CompileConfig
State CompileState
Duration time.Duration
}
type CompileState string
const (
StateWaiting CompileState = "waiting"
StateCompiling CompileState = "compiling"
StateCompressing CompileState = "compressing"
StateDone CompileState = "done"
StateCompileError CompileState = "compile error"
StateCompressError CompileState = "compress error"
)
var (
ColorWaiting = color.New(color.FgHiBlack, color.Italic)
ColorError = color.New(color.FgRed, color.Bold)
ColorInProgress = color.New(color.FgBlue)
ColorDone = color.New(color.FgGreen, color.Bold)
ColorWarn = color.New(color.FgYellow, color.Bold)
)
func (s CompileState) String() string {
switch s {
case StateWaiting:
return ColorWaiting.Sprint(string(s))
case StateCompiling:
return ColorInProgress.Sprint(string(s))
case StateCompressing:
return ColorInProgress.Sprint(string(s))
case StateDone:
return ColorDone.Sprint(string(s))
case StateCompileError:
return ColorError.Sprint(string(s))
case StateCompressError:
return ColorError.Sprint(string(s))
default:
panic("invalid compile state")
}
}