-
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
Draft
BridgeAR
wants to merge
2
commits into
nodejs:main
Choose a base branch
from
BridgeAR:2020-03-17-adhere-to-enforced-colors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.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 agetColorDepth()
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.
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.
Using a boolean for the
color
option will do exactly that. It's only about theauto
mode which ideally checks for the users intent. Using an environment variable is a clear indicator for the user to request a specific mode.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 thegetColorDepth
function? In my own testing I noticed that ifisTTY
is dropped from the condition I get colored output when piping to a non TTY despite not settingFORCE_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.