Skip to content

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

Open
Azatey wants to merge 2 commits into
jorgebucaran:mainfrom
Azatey:main
Open

isColorSupported is showing TRUE for non-tty Windows terminals#97
Azatey wants to merge 2 commits into
jorgebucaran:mainfrom
Azatey:main

Conversation

@Azatey
Copy link
Copy Markdown

@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.

Comment thread index.js
export const isColorSupported =
!isDisabled &&
(isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI)
(isForced || (isWindows && !isDumbTerminal && isTty) || isCompatibleTerminal || isCI)
Copy link
Copy Markdown
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
Copy Markdown
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.

2 participants