Skip to content

Commit

Permalink
Add color choosing support
Browse files Browse the repository at this point in the history
Signed-off-by: Ulysses Souza <[email protected]>
  • Loading branch information
ulyssessouza committed Dec 7, 2021
1 parent 539558b commit 810b74b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
41 changes: 41 additions & 0 deletions util/progress/progressui/colors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package progressui

import (
"os"
"strings"

"github.com/morikuni/aec"
)

var termColorMap = map[string]aec.ANSI{
"": colorRun,
"default": aec.DefaultF,

"black": aec.BlackF,
"red": aec.RedF,
"green": aec.GreenF,
"yellow": aec.YellowF,
"blue": aec.BlueF,
"magenta": aec.MagentaF,
"cyan": aec.CyanF,
"white": aec.WhiteF,

"light-black": aec.LightBlackF,
"light-red": aec.LightRedF,
"light-green": aec.LightGreenF,
"light-yellow": aec.LightYellowF,
"light-blue": aec.LightBlueF,
"light-magenta": aec.LightMagentaF,
"light-cyan": aec.LightCyanF,
"light-white": aec.LightWhiteF,
}


func getTermColor() aec.ANSI {
envColorString := os.Getenv("BUILDKIT_TERM_COLOR")
c, ok := termColorMap[strings.ToLower(envColorString)]
if !ok {
return colorRun
}
return c
}
4 changes: 2 additions & 2 deletions util/progress/progressui/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/containerd/console"
"github.com/moby/buildkit/client"
"github.com/morikuni/aec"
digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/go-digest"
"github.com/tonistiigi/units"
"github.com/tonistiigi/vt100"
"golang.org/x/time/rate"
Expand Down Expand Up @@ -521,7 +521,7 @@ func (disp *display) print(d displayInfo, width, height int, all bool) {

out = align(out, timer, width)
if j.completedTime != nil {
color := colorRun
color := getTermColor()
if j.isCanceled {
color = colorCancel
} else if j.hasError {
Expand Down

0 comments on commit 810b74b

Please sign in to comment.