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

isColorSupported is showing TRUE for non-tty Windows terminals #97

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Azatey
Copy link

@Azatey Azatey commented Jan 4, 2023

Exported isColorSupported property returns wrong value (true) for Windows terminals that has no TTY support, such as Visual Studio Code Output window, etc. That affects libraries, like lint-staged, who rely on it.

The code below should return false for VS Code Output window, but instead returns true:

node -e "console.log(require('colorette').isColorSupported)"

This PR enhances this behavior, by adding additional TTY support check.


const isCI =
"CI" in env &&
("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env)

export const isColorSupported =
!isDisabled &&
(isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI)
(isForced || (isWindows && !isDumbTerminal && isTty) || isCompatibleTerminal || isCI)
Copy link
Owner

Choose a reason for hiding this comment

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

Could we achieve the same result by checking isCompatibleTerminal earlier?

Copy link
Author

Choose a reason for hiding this comment

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

I think not, isCompatibleTerminal will return false both when run through non-TTY GUI app and when through command line directly on Windows. And it seems like Windows console is never TTY either while checked through nodejs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants