Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add terminal color choosing support #2508

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions util/progress/progressui/colors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a convention for this? I know NO_COLOR is a thing but this looks somewhat weird as there isn't just one color. You are changing the color of the completed item but iirc we have 4 possible different colors used by this progressbar.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIC there is not convention on terminal color naming. I just took the ones from "github.com/morikuni/aec" in lower case.

This PR only affects the "typical buildkit blue" color and not the other 3. It's not a complete theme (I actually like the idea of having it 😺).

c, ok := termColorMap[strings.ToLower(envColorString)]
if !ok {
return colorRun
}
return c
}
2 changes: 1 addition & 1 deletion util/progress/progressui/display.go
Original file line number Diff line number Diff line change
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