8000 update supports-color by idranme · Pull Request #579 · chalk/chalk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

update supports-color #579

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

Merged
merged 5 commits into from 8000
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions source/vendor/supports-color/browser.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
/* eslint-env browser */

const isBlinkBasedBrowser = navigator.userAgentData
? navigator.userAgentData.brands.some(({brand}) => brand === 'Chromium')
: /\b(Chrome|Chromium)\//.test(navigator.userAgent);
const level = (() => {
if (navigator.userAgentData) {
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
if (brand && brand.version > 93) {
return 3;
}
}

const colorSupport = isBlinkBasedBrowser ? {
level: 1,
if (/\b(Chrome|Chromium)\//.test(navigator.userAgent)) {
return 1;
}

return 0;
})();

const colorSupport = level !== 0 && {
level,
hasBasic: true,
has256: false,
has16m: false,
} : false;
has256: level >= 2,
has16m: level >= 3,
};

const supportsColor = {
stdout: colorSupport,
Expand Down
12 changes: 6 additions & 6 deletions source/vendor/supports-color/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {WriteStream} from 'node:tty';
import type {WriteStream} from 'node:tty';

export interface Options {
export type Options = {
/**
Whether `process.argv` should be sniffed for `--color` and `--no-color` flags.

@default true
*/
readonly sniffFlags?: boolean;
}
};

/**
Levels:
Expand All @@ -21,7 +21,7 @@ export type ColorSupportLevel = 0 | 1 | 2 | 3;
/**
Detect whether the terminal supports color.
*/
export interface ColorSupport {
export type ColorSupport = {
/**
The color level.
*/
Expand All @@ -41,11 +41,11 @@ export interface ColorSupport {
Whether Truecolor 16 million colors are supported.
*/
has16m: boolean;
}
};

export type ColorInfo = ColorSupport | false;

export function createSupportsColor(stream: WriteStream, options?: Options): ColorInfo;
export function createSupportsColor(stream?: WriteStream, options?: Options): ColorInfo;

declare const supportsColor: {
stdout: ColorInfo;
Expand Down
21 changes: 15 additions & 6 deletions source/vendor/supports-color/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os from 'node:os';
import tty from 'node:tty';

// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
function hasFlag(flag, argv = process.argv) {
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
const position = argv.indexOf(prefix + flag);
const terminatorPosition = argv.indexOf('--');
Expand Down Expand Up @@ -80,6 +80,12 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
}
}

// Check for Azure DevOps pipelines.
// Has to be above the `!streamIsTTY` check.
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
return 1;
}

if (haveStream && !streamIsTTY && forceColor === undefined) {
return 0;
}
Expand All @@ -105,7 +111,11 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
}

if ('CI' in env) {
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
if ('GITHUB_ACTIONS' in env) {
return 3;
}

if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
return 1;
}

Expand All @@ -116,12 +126,11 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
}

// Check for Azure DevOps pipelines
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
return 1;
if (env.COLORTERM === 'truecolor') {
return 3;
}

if (env.COLORTERM === 'truecolor') {
if (env.TERM === 'xterm-kitty') {
return 3;
}

Expand Down
0