-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make terminal colors configurable #2954
Conversation
util/progress/progressui/init.go
Outdated
|
||
func init() { | ||
_, noColorIsSet = os.LookupEnv("NO_COLOR") | ||
_, buildkitColorIsSet = os.LookupEnv("BUILDKIT_COLORS") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing the NO_COLOR
option comes from https://no-color.org/? Might be useful to document that in a comment around it.
Would be good to respect it, but I think the right behavior might be to have BUILDKIT_COLORS
override it if set (specific options should override general options imo)? I also think a BUILDKIT_COLORS=none
option would be good, as a buildkit-specific way of forcing no colors - that could also extend into allowing multiple different "presets" in the future, if that was something we wanted to support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a comment makes sense. I was going back and forth a bit on which variable should take precedence, and personally felt that NO_COLOR
seemed like it should be the winner, as it seemed a bit more likely that an environment might have BUILDKIT_COLORS
defined and then a specific script or pipeline would potentially disable it for one reason or another, but I am happy to change it if the general consensus is that BUILDKIT_COLORS
should win.
Added an example of using RGB values into the first comment.
|
util/progress/progressui/colors.go
Outdated
logrus.Warnf("Could not parse BUILDKIT_COLORS component: %s", strings.Join(parts, "=")) | ||
continue | ||
} | ||
if strings.Contains(parts[1], "=") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure what case this catches? I think this would get caught anyways a bit further down, since it isn't a valid rgb or per-defined color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This catches "warning=yellow=red" or something similar. You are right that it will get caught later, but this error message points more directly at the problem since it will print the whole field and say that it is not parseable. I'd prefer to leave this, instead of falling down to the unknown color error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is identical to the above if
branch, we can merge them to be if len(parts) != 2 || strings.Contains(parts[1], "=") {
@jedevc Cleaned things up a little more and did some additional testing. Let me know if we are in a good enough place to get this in yet. Thanks! |
Some random thoughts;
Finally; w.r.t. the implementation;
|
Users can certainly adjust the background of their terminal, however, if we presume they have the color that they like, then they are unlikely to change it because one program picks a color that is un-readable on a common background choice. At least adjusting the blue to a somewhat lighter blue that is readable on white and black would be a good place to start.
I could absolutely see Docker having support for this across the board, and being able to pass that configuration to the underlying tools/plugins. It seems like underlying tools and libraries like buildkit (and
Eventually, both option seems ideal here. There are some "standard" names that each plugin/application uses internally, like
Based on the discussion in #2508, I used the basic idea of
This is using
I think that we have covered many of the more obvious ones here, and I don't think
It might make sense to check
@thaJeztah This all makes sense. Is this something that would need to happen before a merge? Or as a further iteration on this? Personally, I'd like to at least see a stop-gap get in until there is a more thorough solution that talks to all the good points about future requirements that you have brought up, but to be fair, I am mostly trying to solve an issue that has been plaguing me and I know that you need to consider the broader implications. I'm happy to do a bit more work on this, but I likely won't have the time (or experience) to make this into a robust library for the whole ecosystem.
So, I think this is at least as compatible as the current code is, since I did a quick check on how various terminals behave: The built-in mac terminal does not appear to properly support 24-bit color (as tested with For iterm2 which does appear to support 24-biot colors fine, it also works: |
Note: This PR adds a warning color based on some earlier discussions that referenced #2498. However |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
colorWarning
is causing an issue in the CI so needs to be plugged in or fixed in some other way. I guess if we leave it in there should be a public method to access this color as some warnings are printed outside of progressbar as well.
I don't like with colorWarning
that we are defaulting to the RGB value. This will look off in properly configured terminals where the RGB does not work together with other colors. We should leave defaults only to the predefined names. If there isn't a better option then just leave it to yellow or we can use a different light mode for cancel vs warning.
I made some changes that I think will alleviate the CI issues, and I just switched the default warning color to yellow. It seems like the best choice to stick with the named, 3-bit colors. And orange ends up being yellow when translated to a 3-bit color. |
@tonistiigi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good IMO - just a few nits.
util/progress/progressui/colors.go
Outdated
logrus.Warnf("Could not parse BUILDKIT_COLORS component: %s", strings.Join(parts, "=")) | ||
continue | ||
} | ||
if strings.Contains(parts[1], "=") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is identical to the above if
branch, we can merge them to be if len(parts) != 2 || strings.Contains(parts[1], "=") {
Signed-off-by: Sean P. Kane <[email protected]>
@jedevc I moved the |
When this is merged we can also update this PR against https://no-color.org/ to add buildkit to the projects that support |
util/progress/progressui/display.go
Outdated
@@ -108,6 +108,7 @@ type job struct { | |||
name string | |||
status string | |||
hasError bool | |||
hasWarning bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set it as well. Or if you prefer to do follow-up then add a comment that this is not set yet.
Currently, iiuc the warnings use the default color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tonistiigi Is there a reliable way that I can generate a buildkit warning during a build using buildctl
that I could use for testing?
I'm not sure whether I'll be able to wire the warning functionality all the way through, but I can certainly give it a try. If not, I'll go ahead and add the comment and leave it for a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and added a comment to hasWarning
for the moment.
Signed-off-by: Sean P. Kane <[email protected]>
@tonistiigi @jedevc I think this is good to merge at this point. Please let me know if there is anything else that you need from me. I'd also be interested in knowing roughly when a new release of |
This is a new feature so would not be picked for v0.10.4 but needs to wait for v0.11. Buildx release should be coming soon though https://github.com/docker/buildx/pulls?q=is%3Aopen+is%3Apr+milestone%3Av0.9.0 and we can consider vendoring client libs from master to get the latest updates for it. |
@tonistiigi Thank for getting this merged and letting me know what the release schedule looks like! |
This pull request is inspired by the work and conversation here: #2508
I did not want to stomp over the existing work, but since it has been many months and I had some time, I thought I would try my hand at it. Let me know if this is a reasonable starting place.
The NO_COLOR implementation needs more work, as it is using ANSI still, but just the default off-white for everything. I'd also be happy to pull it out of here for the moment, just so we can get the general color configuration support merged in.UPDATED: The
NO_COLOR
implementation is now correctly avoiding the use of any ANSI colors.This at least partially addresses some of the features here: docker/roadmap#301
cc/ @ulyssessouza @tonistiigi @crazy-max
Default colors (non-windows):
User-defined colors using names:
User-defined colors using RGB values and names:
NO_COLOR defined (even with user-defined colors also set):
Example Usage
From the root of this repo:
NOTE: Once this is merged we can also update this PR against https://no-color.org/ to add buildkit to the projects that support
NO_COLOR
. UPDATED: Done!