-
Notifications
You must be signed in to change notification settings - Fork 82
Vendor chalk and supports-color #659
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
Open
jfmengels
wants to merge
41
commits into
rtfeldman:master
Choose a base branch
from
jfmengels:chalk-pr
base: master
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.
Open
Changes from 22 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
89bc5da
Vendor chalk
jfmengels 7b9598c
Format chalk with prettier
jfmengels 33f2a7a
Vendor supports-color
jfmengels 901128e
Format supports-color with prettier
jfmengels 9df75a0
Simplify chalk to the project's usage
jfmengels 7b714cd
Inline has-flag dependency
jfmengels 1780c22
Simplify hasFlag
jfmengels e798ae3
Add -- to flags
jfmengels 49398a4
Ignore terminatorPosition
jfmengels 24c1222
Use includes()
jfmengels 8467e1f
Simplify supports-color to project's usage
jfmengels 04f7e88
Remove sniffFlags
jfmengels 6727817
Move flagForceColor to inside _supportsColor
jfmengels 488ca1f
Move computation for flagForceColor in else condition
jfmengels 5942ad1
Merge flagForceColor and noFlagForceColor
jfmengels 5d72b6c
Merge flagForceColor and forceColor
jfmengels c0d4825
Remove options and simplify arguments
jfmengels 859ecb9
Require os only when necessary
jfmengels 5a53966
Use booleans instead of numbers
jfmengels e86a30e
Return early
jfmengels 3688215
Simplify branches
jfmengels 9fc1ba2
Indicate where to find more styles
jfmengels 249e2fb
Add flow checks for chalk
jfmengels 09210f9
Don't check for invalid CLI flags
jfmengels c513665
Simplify FORCE_COLOR checks
jfmengels d63d47d
Check for forceColor undefined early
jfmengels 44e73b3
Inline min
jfmengels b6ae380
Assume all terminals support colors
jfmengels 8b43284
Check for tty when needed
jfmengels c675487
Assume all CIs support colors
jfmengels 02a06d8
Switch branches
jfmengels ff53beb
Merge 2 functions
jfmengels 80e0f4b
Switch branches
jfmengels 5d745b6
Use return statement
jfmengels bc6d98e
Replace tty.isatty(1) with process.stdout.isTTY
lydell 04d52fd
Join two ifs into one
lydell 279c6eb
Enable flow
lydell c170593
Merge branch 'master' into chalk-pr
lydell e1fecc0
Update package-lock.json
lydell 5ac9553
Change isTTY flow to appease Flow
lydell 856c838
Help Flow understand a boolean is a boolean
lydell 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 'use strict'; | ||
| const supportsColor = require('./supports-color'); | ||
|
|
||
| // Find more colors/styles in | ||
| // https://github.com/chalk/ansi-styles/blob/main/index.js | ||
| const colors = { | ||
| blue: { open: '\x1B[34m', close: '\x1B[39m' }, | ||
| red: { open: '\x1B[31m', close: '\x1B[39m' }, | ||
| }; | ||
|
|
||
| const chalk = { supportsColor }; | ||
|
|
||
| for (const [styleName, style] of Object.entries(colors)) { | ||
| chalk[styleName] = (string) => { | ||
| if (!supportsColor || !string) { | ||
| return string; | ||
| } | ||
|
|
||
| return style.open + string + style.close; | ||
| }; | ||
| } | ||
|
|
||
| module.exports = chalk; | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| 'use strict'; | ||
| /** | ||
| Based on https://github.com/chalk/supports-color v10.2.2 | ||
| but adapted to use CommonJs and simplified to our needs (only knowing whether stdout supports colors). | ||
|
|
||
| MIT License | ||
|
|
||
| Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com) | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| */ | ||
| const tty = require('tty'); | ||
|
|
||
| const { env } = process; | ||
|
|
||
| function envForceColor() { | ||
| if (!('FORCE_COLOR' in env)) { | ||
| return; | ||
| } | ||
|
|
||
| if (env.FORCE_COLOR === 'true') { | ||
| return true; | ||
| } | ||
|
|
||
| if (env.FORCE_COLOR === 'false') { | ||
| return false; | ||
| } | ||
|
|
||
| if (env.FORCE_COLOR.length === 0) { | ||
| return true; | ||
| } | ||
|
|
||
| const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3); | ||
|
|
||
| if (![0, 1, 2, 3].includes(level)) { | ||
| return; | ||
| } | ||
|
|
||
| return level !== 0; | ||
| } | ||
|
|
||
| function _supportsColor(streamIsTTY) { | ||
| let forceColor = envForceColor(); | ||
| if (forceColor === undefined) { | ||
| if ( | ||
| process.argv.includes('--no-color') || | ||
| process.argv.includes('--no-colors') || | ||
| process.argv.includes('--color=false') || | ||
| process.argv.includes('--color=never') | ||
| ) { | ||
| return false; | ||
| } else if ( | ||
| process.argv.includes('--color') || | ||
| process.argv.includes('--colors') || | ||
| process.argv.includes('--color=true') || | ||
| process.argv.includes('--color=always') | ||
| ) { | ||
| forceColor = true; | ||
| } | ||
| } | ||
|
|
||
| if (forceColor === false) { | ||
| return false; | ||
| } | ||
|
|
||
| if ( | ||
| process.argv.includes('--color=16m') || | ||
| process.argv.includes('--color=full') || | ||
| process.argv.includes('--color=truecolor') || | ||
| process.argv.includes('--color=256') | ||
| ) { | ||
| return true; | ||
| } | ||
|
|
||
| // Check for Azure DevOps pipelines. | ||
| // Has to be above the `!streamIsTTY` check. | ||
| if ('TF_BUILD' in env && 'AGENT_NAME' in env) { | ||
| return true; | ||
| } | ||
|
|
||
| if (!streamIsTTY && forceColor === undefined) { | ||
| return false; | ||
| } | ||
|
|
||
| if (process.platform === 'win32') { | ||
| return true; | ||
| } | ||
|
|
||
| const min = forceColor || false; | ||
|
|
||
| if (env.TERM === 'dumb') { | ||
| return min; | ||
| } | ||
|
|
||
| if ('CI' in env) { | ||
| if ( | ||
| ['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some((key) => key in env) | ||
| ) { | ||
| return true; | ||
| } | ||
|
|
||
| if ( | ||
| ['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some( | ||
| (sign) => sign in env | ||
| ) || | ||
| env.CI_NAME === 'codeship' | ||
| ) { | ||
| return true; | ||
| } | ||
|
|
||
| return min; | ||
| } | ||
|
|
||
| if ('TEAMCITY_VERSION' in env) { | ||
| return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION); | ||
| } | ||
|
|
||
| if ( | ||
| env.COLORTERM === 'truecolor' || | ||
| env.TERM === 'xterm-kitty' || | ||
| env.TERM === 'xterm-ghostty' || | ||
| env.TERM === 'wezterm' | ||
| ) { | ||
| return true; | ||
| } | ||
| if ('TERM_PROGRAM' in env) { | ||
| switch (env.TERM_PROGRAM) { | ||
| case 'iTerm.app': | ||
| case 'Apple_Terminal': { | ||
| return true; | ||
| } | ||
| // No default | ||
| } | ||
| } | ||
|
|
||
| if ( | ||
| /-256(color)?$/i.test(env.TERM) || | ||
| /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test( | ||
| env.TERM | ||
| ) || | ||
| 'COLORTERM' in env | ||
| ) { | ||
| return true; | ||
| } | ||
|
|
||
| return min; | ||
| } | ||
|
|
||
| module.exports = _supportsColor(tty.isatty(1)); |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.