-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
console: adhere to environment variables enforcing colors #32308
base: main
Are you sure you want to change the base?
console: adhere to environment variables enforcing colors #32308
Conversation
52717ac
to
516e851
Compare
Make sure the console color `auto` mode checks the environment variables if any enforces (de)activation of colors.
516e851
to
97dc3ef
Compare
@@ -266,9 +269,14 @@ const kNoColorInspectOptions = {}; | |||
Console.prototype[kGetInspectOptions] = function(stream) { | |||
let color = this[kColorMode]; | |||
if (color === 'auto') { | |||
color = stream.isTTY && ( |
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 check should not be dropped.
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.
The intention of this PR is to circumvent this check. This is a semver-major PR to adhere to the environment variables. Those should always come first, no matter what kind of stream is used. Otherwise it's not possible to fully (de)activate colors using environment variables.
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.
Those should always come first, no matter what kind of stream is used.
I’m -1 on this, sorry. Console
instances should be as self-contained as possible, relying on external state like environment variables is counterintuitive imo and breaks orthogonality.
Otherwise it's not possible to fully (de)activate colors using environment variables.
Right, but I don’t think that should be the case. Custom Console
instances should adhere to their options and nothing else.
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 will only change the behavior under the following circumstances:
Colors will not be printed anymore when deactivated with environment variables (FORCE_COLOR
, NODE_DISABLE_COLORS
, NO_COLOR
) for TTY streams that do not have a getColorDepth()
function.
Colors will be printed when activated with the FORCE_COLOR
environment variable for all streams.
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.
Colors will be printed when activated with the
FORCE_COLOR
environment variable for all streams.
Right – what I’m saying is that I’m -1 on this specifically (because, again, that breaks orthogonality).
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.
Right, but I don’t think that should be the case. Custom Console instances should adhere to their options and nothing else.
Using a boolean for the color
option will do exactly that. It's only about the auto
mode which ideally checks for the users intent. Using an environment variable is a clear indicator for the user to request a specific mode.
I’m -1 on this, sorry. Console instances should be as self-contained as possible, relying on external state like environment variables is counterintuitive imo and breaks orthogonality.
But it's still going to be self-contained? The current behavior seems counter-intuitive to me. I would expect environment variables to clearly have an impact on default values. It is one of the strongest possible ways a user is able to request a general behavior.
I'll open a twitter survey to get a bigger opinion pool.
We often use environment variables to override the default value. This is what is also suggested here.
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 think Anna's point is that there's no inherent connection between the stream a Console is using and the process's env (they are orthogonal), so even if the mode is auto, using data from the env is nonsensical.
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.
Hey, sorry to necrobump, but I really don't follow the reasoning behind console checking whether a stream is a TTY before calling the getColorDepth
function if it exists and is a function. Why does it matter that the environment is orthogonal to the console when the responsibility to determine if colors should be used are handed off to the getColorDepth
function? In my own testing I noticed that if isTTY
is dropped from the condition I get colored output when piping to a non TTY despite not setting FORCE_COLOR
so there is more to it than just dropping that part of the expression to get a behavior that corresponds to my interpretation of the manual.
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've just сame across the discussion regarding the proposed change to the console color auto mode, and I'd like to express my support for the modification.
The goal of ensuring that the console color auto mode considers environment variables for (de)activating colors is a valuable one.
Here's why I believe this change is beneficial:
Clarity and Predictability: When users set environment variables like FORCE_COLOR, NODE_DISABLE_COLORS, or NO_COLOR, they have a clear intention regarding color output. By checking these variables, the console can align itself with the user's preferences.
User Empowerment: Allowing users to control color output through environment variables empowers them to customize their development environment to suit their needs. It's in line with the philosophy of "configuration over convention."
Consistency: This change promotes consistency by ensuring that environment variables take precedence. Regardless of the stream type (TTY or non-TTY), the user's color preferences are respected.
I believe that by implementing this change, the console becomes more versatile and user-friendly. While it's essential to maintain self-contained behavior in most cases, it's equally important to provide flexibility to accommodate diverse development environments and individual preferences.
Ultimately, using environment variables to influence default behaviors is a common practice in many software projects. It's a powerful way for users to communicate their intent and align tools with their expectations.
8ae28ff
to
2935f72
Compare
Make sure the console color
auto
mode checks the environmentvariables if any enforces (de)activation of colors.
Fatal errors will also check for the environment variables from now on.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes