Compare commits
155 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa06bb5ac3 | ||
|
|
51557784b8 | ||
|
|
5c91505e18 | ||
|
|
a8f5bf7a67 | ||
|
|
67db246ae0 | ||
|
|
79ee2d386c | ||
|
|
5dbc1e2633 | ||
|
|
4ebb62d1ca | ||
|
|
fc809b686d | ||
|
|
83acfcf8cb | ||
|
|
f8381204fb | ||
|
|
4a10354857 | ||
|
|
77126fba13 | ||
|
|
795273f17a | ||
|
|
386909ee0b | ||
|
|
2db3c7701e | ||
|
|
f7b29ae8ef | ||
|
|
f399cd0ff6 | ||
|
|
72c742d471 | ||
|
|
5aafc0af74 | ||
|
|
df0e69df51 | ||
|
|
29b856959f | ||
|
|
a370f468a4 | ||
|
|
7443e9faa0 | ||
|
|
a027e3c1e0 | ||
|
|
79c56dfc1e | ||
|
|
c3d14f9ea8 | ||
|
|
158bf4429e | ||
|
|
a34bcf6327 | ||
|
|
1b4cd21fb1 | ||
|
|
6e0df055f4 | ||
|
|
92c55db46f | ||
|
|
d7d75717b3 | ||
|
|
96f44c976b | ||
|
|
c2311622c3 | ||
|
|
ba5c385ecf | ||
|
|
503b9d35cd | ||
|
|
b17d862944 | ||
|
|
d28690e66b | ||
|
|
bccde97f8a | ||
|
|
85f7e96f75 | ||
|
|
4d5c4795ad | ||
|
|
7a6893551d | ||
|
|
04fdbd6d8d | ||
|
|
d7c4aac07e | ||
|
|
09fd5c4ba8 | ||
|
|
c987c61486 | ||
|
|
f478655c3c | ||
|
|
3761e455a1 | ||
|
|
95217429be | ||
|
|
625a285772 | ||
|
|
48d25d156a | ||
|
|
b68c8b5102 | ||
|
|
f8a3642a81 | ||
|
|
4cf2e40e07 | ||
|
|
0fba91b037 | ||
|
|
d798222a5a | ||
|
|
fa16f4ec37 | ||
|
|
4dab5e1fb6 | ||
|
|
9bf298571e | ||
|
|
2a9abb18f4 | ||
|
|
97a0861848 | ||
|
|
0433fcff2a | ||
|
|
d5fb377019 | ||
|
|
ca330532ec | ||
|
|
e304e8c230 | ||
|
|
02abeebac3 | ||
|
|
72299f99a0 | ||
|
|
c0d8e7ed8a | ||
|
|
b31d6fb48a | ||
|
|
445092f9af | ||
|
|
4c3df88472 | ||
|
|
09ddbadcb5 | ||
|
|
55816cdd4d | ||
|
|
31fa942080 | ||
|
|
61999a4e77 | ||
|
|
f0f4638a92 | ||
|
|
7f21f209da | ||
|
|
63469d30e4 | ||
|
|
797461ee32 | ||
|
|
0e6fecc7f7 | ||
|
|
20002d8bd1 | ||
|
|
b3930189a5 | ||
|
|
18c280da2e | ||
|
|
628b5954cf | ||
|
|
4de1841129 | ||
|
|
fb8e85ab87 | ||
|
|
eef8c8c191 | ||
|
|
48905d0805 | ||
|
|
1953816afd | ||
|
|
61aca7cb76 | ||
|
|
4e65299e7b | ||
|
|
2a53389d72 | ||
|
|
6b4d20683f | ||
|
|
1f77953f1a | ||
|
|
87156ce8e2 | ||
|
|
c25c32a25f | ||
|
|
655653bb0c | ||
|
|
af4a078245 | ||
|
|
c08417e88c | ||
|
|
983094883c | ||
|
|
e2dd171597 | ||
|
|
d82b2a6638 | ||
|
|
4ab4665994 | ||
|
|
4990a3578a | ||
|
|
b3e9b91405 | ||
|
|
d3be9c65b1 | ||
|
|
98628d9f08 | ||
|
|
7b9211be50 | ||
|
|
cd5de7a2f6 | ||
|
|
2ca015c4c5 | ||
|
|
3ef170b457 | ||
|
|
de2f4cd606 | ||
|
|
60959e05cf | ||
|
|
7f6e5630b0 | ||
|
|
587a5fbcbb | ||
|
|
076f0c9eb6 | ||
|
|
1284415013 | ||
|
|
cf6615647a | ||
|
|
4726b1bfda | ||
|
|
90c7a92ff1 | ||
|
|
f590a65489 | ||
|
|
70bb378e8e | ||
|
|
b827cb0817 | ||
|
|
1542c85f1b | ||
|
|
8a090d7885 | ||
|
|
b9c95dbfd2 | ||
|
|
6a14c58e54 | ||
|
|
2a678789b1 | ||
|
|
0307f263cb | ||
|
|
70f22d87ba | ||
|
|
a2b5fa22dc | ||
|
|
a6ad945452 | ||
|
|
48ba5b0b9b | ||
|
|
01cfb5c888 | ||
|
|
fc9a7e369b | ||
|
|
af8b3657e9 | ||
|
|
7c6f83f719 | ||
|
|
58483b5ab1 | ||
|
|
0dae4c28e1 | ||
|
|
84f27d4bd8 | ||
|
|
245dfa5c6f | ||
|
|
e80f02e2dd | ||
|
|
925397a0f5 | ||
|
|
52823001a5 | ||
|
|
12d1276b36 | ||
|
|
576d8d2171 | ||
|
|
ae8a03f2c5 | ||
|
|
b55dd79f8b | ||
|
|
678152cf19 | ||
|
|
011dd0421e | ||
|
|
6554030550 | ||
|
|
bc3dd75329 | ||
|
|
a8c60e37fa | ||
|
|
5392313414 |
38 changed files with 1915 additions and 1097 deletions
3
.gitattributes
vendored
3
.gitattributes
vendored
|
|
@ -1,2 +1 @@
|
|||
* text=auto
|
||||
*.js text eol=lf
|
||||
* text=auto eol=lf
|
||||
|
|
|
|||
4
.github/funding.yml
vendored
Normal file
4
.github/funding.yml
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
github: [sindresorhus, Qix-]
|
||||
open_collective: sindresorhus
|
||||
tidelift: npm/chalk
|
||||
custom: https://sindresorhus.com/donate
|
||||
3
.github/security.md
vendored
Normal file
3
.github/security.md
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Security Policy
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
||||
26
.github/workflows/main.yml
vendored
Normal file
26
.github/workflows/main.yml
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
name: CI
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
jobs:
|
||||
test:
|
||||
name: Node.js ${{ matrix.node-version }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version:
|
||||
- 18
|
||||
- 16
|
||||
- 14
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
- uses: codecov/codecov-action@v2
|
||||
if: matrix.node-version == 16
|
||||
with:
|
||||
fail_ci_if_error: true
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- '8'
|
||||
- '6'
|
||||
- '4'
|
||||
after_success: npm run coveralls
|
||||
55
benchmark.js
55
benchmark.js
|
|
@ -1,24 +1,57 @@
|
|||
/* globals set bench */
|
||||
'use strict';
|
||||
const chalk = require('.');
|
||||
/* globals suite, bench */
|
||||
import chalk from './index.js';
|
||||
|
||||
suite('chalk', () => {
|
||||
set('iterations', 100000);
|
||||
const chalkRed = chalk.red;
|
||||
const chalkBgRed = chalk.bgRed;
|
||||
const chalkBlueBgRed = chalk.blue.bgRed;
|
||||
const chalkBlueBgRedBold = chalk.blue.bgRed.bold;
|
||||
|
||||
bench('single style', () => {
|
||||
const blueStyledString = 'the fox jumps' + chalk.blue('over the lazy dog') + '!';
|
||||
|
||||
bench('1 style', () => {
|
||||
chalk.red('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('several styles', () => {
|
||||
bench('2 styles', () => {
|
||||
chalk.blue.bgRed('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('3 styles', () => {
|
||||
chalk.blue.bgRed.bold('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
const cached = chalk.blue.bgRed.bold;
|
||||
bench('cached styles', () => {
|
||||
cached('the fox jumps over the lazy dog');
|
||||
bench('cached: 1 style', () => {
|
||||
chalkRed('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('nested styles', () => {
|
||||
chalk.red('the fox jumps', chalk.underline.bgBlue('over the lazy dog') + '!');
|
||||
bench('cached: 2 styles', () => {
|
||||
chalkBlueBgRed('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('cached: 3 styles', () => {
|
||||
chalkBlueBgRedBold('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('cached: 1 style with newline', () => {
|
||||
chalkRed('the fox jumps\nover the lazy dog');
|
||||
});
|
||||
|
||||
bench('cached: 1 style nested intersecting', () => {
|
||||
chalkRed(blueStyledString);
|
||||
});
|
||||
|
||||
bench('cached: 1 style nested non-intersecting', () => {
|
||||
chalkBgRed(blueStyledString);
|
||||
});
|
||||
|
||||
bench('cached: 1 style template literal', () => {
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
chalkRed`the fox jumps over the lazy dog`;
|
||||
});
|
||||
|
||||
bench('cached: nested styles template literal', () => {
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
chalkRed`the fox {bold jumps} over the {underline lazy} dog`;
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,38 +1,38 @@
|
|||
'use strict';
|
||||
const chalk = require('..');
|
||||
import {setTimeout as delay} from 'node:timers/promises';
|
||||
import convertColor from 'color-convert';
|
||||
import updateLog from 'log-update';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
const ignoreChars = /[^!-~]/;
|
||||
const ignoreChars = /[^!-~]/g;
|
||||
|
||||
function rainbow(str, offset) {
|
||||
if (!str || str.length === 0) {
|
||||
return str;
|
||||
function rainbow(string, offset) {
|
||||
if (!string || string.length === 0) {
|
||||
return string;
|
||||
}
|
||||
|
||||
const hueStep = 360 / str.replace(ignoreChars, '').length;
|
||||
const hueStep = 360 / string.replaceAll(ignoreChars, '').length;
|
||||
|
||||
let hue = offset % 360;
|
||||
const chars = [];
|
||||
for (const c of str) {
|
||||
if (c.match(ignoreChars)) {
|
||||
chars.push(c);
|
||||
const characters = [];
|
||||
for (const character of string) {
|
||||
if (ignoreChars.test(character)) {
|
||||
characters.push(character);
|
||||
} else {
|
||||
chars.push(chalk.hsl(hue, 100, 50)(c));
|
||||
characters.push(chalk.hex(convertColor.hsl.hex(hue, 100, 50))(character));
|
||||
hue = (hue + hueStep) % 360;
|
||||
}
|
||||
}
|
||||
|
||||
return chars.join('');
|
||||
return characters.join('');
|
||||
}
|
||||
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
async function animateString(str) {
|
||||
console.log();
|
||||
for (let i = 0; i < 360 * 5; i++) {
|
||||
console.log('\u001B[1F\u001B[G ', rainbow(str, i));
|
||||
await sleep(2); // eslint-disable-line no-await-in-loop
|
||||
async function animateString(string) {
|
||||
for (let index = 0; index < 360 * 5; index++) {
|
||||
updateLog(rainbow(string, index));
|
||||
await delay(2); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
}
|
||||
|
||||
console.log();
|
||||
animateString('We hope you enjoy the new version of Chalk 2! <3').then(() => console.log());
|
||||
await animateString('We hope you enjoy Chalk! <3');
|
||||
console.log();
|
||||
|
|
|
|||
|
|
@ -1,18 +1,27 @@
|
|||
'use strict';
|
||||
const chalk = require('..');
|
||||
const styles = require('ansi-styles');
|
||||
import process from 'node:process';
|
||||
import styles from 'ansi-styles';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
// Generates screenshot
|
||||
for (const key of Object.keys(styles)) {
|
||||
let ret = key;
|
||||
let returnValue = key;
|
||||
|
||||
if (key === 'reset' || key === 'hidden' || key === 'grey') {
|
||||
// We skip `overline` as almost no terminal supports it so we cannot show it off.
|
||||
if (
|
||||
key === 'reset'
|
||||
|| key === 'hidden'
|
||||
|| key === 'grey'
|
||||
|| key === 'bgGray'
|
||||
|| key === 'bgGrey'
|
||||
|| key === 'overline'
|
||||
|| key.endsWith('Bright')
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (/^bg[^B]/.test(key)) {
|
||||
ret = chalk.black(ret);
|
||||
returnValue = chalk.black(returnValue);
|
||||
}
|
||||
|
||||
process.stdout.write(chalk[key](ret) + ' ');
|
||||
process.stdout.write(chalk[key](returnValue) + ' ');
|
||||
}
|
||||
|
|
|
|||
228
index.js
228
index.js
|
|
@ -1,228 +0,0 @@
|
|||
'use strict';
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
const ansiStyles = require('ansi-styles');
|
||||
const supportsColor = require('supports-color');
|
||||
|
||||
const template = require('./templates.js');
|
||||
|
||||
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
|
||||
|
||||
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
||||
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
|
||||
|
||||
// `color-convert` models to exclude from the Chalk API due to conflicts and such
|
||||
const skipModels = new Set(['gray']);
|
||||
|
||||
const styles = Object.create(null);
|
||||
|
||||
function applyOptions(obj, options) {
|
||||
options = options || {};
|
||||
|
||||
// Detect level if not set manually
|
||||
const scLevel = supportsColor ? supportsColor.level : 0;
|
||||
obj.level = options.level === undefined ? scLevel : options.level;
|
||||
obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
|
||||
}
|
||||
|
||||
function Chalk(options) {
|
||||
// We check for this.template here since calling `chalk.constructor()`
|
||||
// by itself will have a `this` of a previously constructed chalk object
|
||||
if (!this || !(this instanceof Chalk) || this.template) {
|
||||
const chalk = {};
|
||||
applyOptions(chalk, options);
|
||||
|
||||
chalk.template = function () {
|
||||
const args = [].slice.call(arguments);
|
||||
return chalkTag.apply(null, [chalk.template].concat(args));
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(chalk, Chalk.prototype);
|
||||
Object.setPrototypeOf(chalk.template, chalk);
|
||||
|
||||
chalk.template.constructor = Chalk;
|
||||
|
||||
return chalk.template;
|
||||
}
|
||||
|
||||
applyOptions(this, options);
|
||||
}
|
||||
|
||||
// Use bright blue on Windows as the normal blue color is illegible
|
||||
if (isSimpleWindowsTerm) {
|
||||
ansiStyles.blue.open = '\u001B[94m';
|
||||
}
|
||||
|
||||
for (const key of Object.keys(ansiStyles)) {
|
||||
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
|
||||
|
||||
styles[key] = {
|
||||
get() {
|
||||
const codes = ansiStyles[key];
|
||||
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
styles.visible = {
|
||||
get() {
|
||||
return build.call(this, this._styles || [], true, 'visible');
|
||||
}
|
||||
};
|
||||
|
||||
ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
|
||||
for (const model of Object.keys(ansiStyles.color.ansi)) {
|
||||
if (skipModels.has(model)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
styles[model] = {
|
||||
get() {
|
||||
const level = this.level;
|
||||
return function () {
|
||||
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
|
||||
const codes = {
|
||||
open,
|
||||
close: ansiStyles.color.close,
|
||||
closeRe: ansiStyles.color.closeRe
|
||||
};
|
||||
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
|
||||
for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
|
||||
if (skipModels.has(model)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
||||
styles[bgModel] = {
|
||||
get() {
|
||||
const level = this.level;
|
||||
return function () {
|
||||
const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
|
||||
const codes = {
|
||||
open,
|
||||
close: ansiStyles.bgColor.close,
|
||||
closeRe: ansiStyles.bgColor.closeRe
|
||||
};
|
||||
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const proto = Object.defineProperties(() => {}, styles);
|
||||
|
||||
function build(_styles, _empty, key) {
|
||||
const builder = function () {
|
||||
return applyStyle.apply(builder, arguments);
|
||||
};
|
||||
|
||||
builder._styles = _styles;
|
||||
builder._empty = _empty;
|
||||
|
||||
const self = this;
|
||||
|
||||
Object.defineProperty(builder, 'level', {
|
||||
enumerable: true,
|
||||
get() {
|
||||
return self.level;
|
||||
},
|
||||
set(level) {
|
||||
self.level = level;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(builder, 'enabled', {
|
||||
enumerable: true,
|
||||
get() {
|
||||
return self.enabled;
|
||||
},
|
||||
set(enabled) {
|
||||
self.enabled = enabled;
|
||||
}
|
||||
});
|
||||
|
||||
// See below for fix regarding invisible grey/dim combination on Windows
|
||||
builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';
|
||||
|
||||
// `__proto__` is used because we must return a function, but there is
|
||||
// no way to create a function with a different prototype
|
||||
builder.__proto__ = proto; // eslint-disable-line no-proto
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
function applyStyle() {
|
||||
// Support varags, but simply cast to string in case there's only one arg
|
||||
const args = arguments;
|
||||
const argsLen = args.length;
|
||||
let str = String(arguments[0]);
|
||||
|
||||
if (argsLen === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (argsLen > 1) {
|
||||
// Don't slice `arguments`, it prevents V8 optimizations
|
||||
for (let a = 1; a < argsLen; a++) {
|
||||
str += ' ' + args[a];
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.enabled || this.level <= 0 || !str) {
|
||||
return this._empty ? '' : str;
|
||||
}
|
||||
|
||||
// Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
|
||||
// see https://github.com/chalk/chalk/issues/58
|
||||
// If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
|
||||
const originalDim = ansiStyles.dim.open;
|
||||
if (isSimpleWindowsTerm && this.hasGrey) {
|
||||
ansiStyles.dim.open = '';
|
||||
}
|
||||
|
||||
for (const code of this._styles.slice().reverse()) {
|
||||
// Replace any instances already present with a re-opening code
|
||||
// otherwise only the part of the string until said closing code
|
||||
// will be colored, and the rest will simply be 'plain'.
|
||||
str = code.open + str.replace(code.closeRe, code.open) + code.close;
|
||||
|
||||
// Close the styling before a linebreak and reopen
|
||||
// after next line to fix a bleed issue on macOS
|
||||
// https://github.com/chalk/chalk/pull/92
|
||||
str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
|
||||
}
|
||||
|
||||
// Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
|
||||
ansiStyles.dim.open = originalDim;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
function chalkTag(chalk, strings) {
|
||||
if (!Array.isArray(strings)) {
|
||||
// If chalk() was called by itself or with a string,
|
||||
// return the string itself as a string.
|
||||
return [].slice.call(arguments, 1).join(' ');
|
||||
}
|
||||
|
||||
const args = [].slice.call(arguments, 2);
|
||||
const parts = [strings.raw[0]];
|
||||
|
||||
for (let i = 1; i < strings.length; i++) {
|
||||
parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
|
||||
parts.push(String(strings.raw[i]));
|
||||
}
|
||||
|
||||
return template(chalk, parts.join(''));
|
||||
}
|
||||
|
||||
Object.defineProperties(Chalk.prototype, styles);
|
||||
|
||||
module.exports = Chalk(); // eslint-disable-line new-cap
|
||||
module.exports.supportsColor = supportsColor;
|
||||
module.exports.default = module.exports; // For TypeScript
|
||||
2
license
2
license
|
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
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:
|
||||
|
||||
|
|
|
|||
BIN
media/screenshot.png
Normal file
BIN
media/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 235 KiB |
69
package.json
69
package.json
|
|
@ -1,21 +1,32 @@
|
|||
{
|
||||
"name": "chalk",
|
||||
"version": "2.3.0",
|
||||
"version": "5.6.2",
|
||||
"description": "Terminal string styling done right",
|
||||
"license": "MIT",
|
||||
"repository": "chalk/chalk",
|
||||
"funding": "https://github.com/chalk/chalk?sponsor=1",
|
||||
"type": "module",
|
||||
"main": "./source/index.js",
|
||||
"exports": "./source/index.js",
|
||||
"imports": {
|
||||
"#ansi-styles": "./source/vendor/ansi-styles/index.js",
|
||||
"#supports-color": {
|
||||
"node": "./source/vendor/supports-color/index.js",
|
||||
"default": "./source/vendor/supports-color/browser.js"
|
||||
}
|
||||
},
|
||||
"types": "./source/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
"node": "^12.17.0 || ^14.13 || >=16.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && tsc --project types && nyc ava",
|
||||
"bench": "matcha benchmark.js",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
||||
"test": "xo && c8 ava && tsd",
|
||||
"bench": "matcha benchmark.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"templates.js",
|
||||
"types/index.d.ts"
|
||||
"source",
|
||||
"!source/index.test-d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"color",
|
||||
|
|
@ -25,7 +36,6 @@
|
|||
"console",
|
||||
"cli",
|
||||
"string",
|
||||
"str",
|
||||
"ansi",
|
||||
"style",
|
||||
"styles",
|
||||
|
|
@ -40,27 +50,34 @@
|
|||
"command-line",
|
||||
"text"
|
||||
],
|
||||
"dependencies": {
|
||||
"ansi-styles": "^3.1.0",
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
"supports-color": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"coveralls": "^3.0.0",
|
||||
"execa": "^0.8.0",
|
||||
"import-fresh": "^2.0.0",
|
||||
"@types/node": "^16.11.10",
|
||||
"ava": "^3.15.0",
|
||||
"c8": "^7.10.0",
|
||||
"color-convert": "^2.0.1",
|
||||
"execa": "^6.0.0",
|
||||
"log-update": "^5.0.0",
|
||||
"matcha": "^0.7.0",
|
||||
"nyc": "^11.0.2",
|
||||
"resolve-from": "^4.0.0",
|
||||
"typescript": "^2.5.3",
|
||||
"xo": "*"
|
||||
"tsd": "^0.19.0",
|
||||
"xo": "^0.57.0",
|
||||
"yoctodelay": "^2.0.0"
|
||||
},
|
||||
"types": "types/index.d.ts",
|
||||
"xo": {
|
||||
"envs": [
|
||||
"node",
|
||||
"mocha"
|
||||
"rules": {
|
||||
"unicorn/prefer-string-slice": "off",
|
||||
"@typescript-eslint/consistent-type-imports": "off",
|
||||
"@typescript-eslint/consistent-type-exports": "off",
|
||||
"@typescript-eslint/consistent-type-definitions": "off",
|
||||
"unicorn/expiring-todo-comments": "off"
|
||||
}
|
||||
},
|
||||
"c8": {
|
||||
"reporter": [
|
||||
"text",
|
||||
"lcov"
|
||||
],
|
||||
"exclude": [
|
||||
"source/vendor"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
196
readme.md
196
readme.md
|
|
@ -1,7 +1,7 @@
|
|||
<h1 align="center">
|
||||
<br>
|
||||
<br>
|
||||
<img width="320" src="https://cdn.rawgit.com/chalk/chalk/19935d6484811c5e468817f846b7b3d417d7bf4a/logo.svg" alt="chalk">
|
||||
<img width="320" src="media/logo.svg" alt="Chalk">
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
|
|
@ -9,37 +9,42 @@
|
|||
|
||||
> Terminal string styling done right
|
||||
|
||||
[](https://travis-ci.org/chalk/chalk) [](https://coveralls.io/github/chalk/chalk?branch=master) [](https://www.youtube.com/watch?v=9auOCbH5Ns4) [](https://github.com/sindresorhus/xo) [](https://github.com/sindresorhus/awesome-nodejs)
|
||||
[](https://codecov.io/gh/chalk/chalk)
|
||||
[](https://www.npmjs.com/package/chalk?activeTab=dependents)
|
||||
[](https://www.npmjs.com/package/chalk)
|
||||
|
||||
### [See what's new in Chalk 2](https://github.com/chalk/chalk/releases/tag/v2.0.0)
|
||||

|
||||
|
||||

|
||||
## Info
|
||||
|
||||
- [Why not switch to a smaller coloring package?](https://github.com/chalk/chalk?tab=readme-ov-file#why-not-switch-to-a-smaller-coloring-package)
|
||||
- See [yoctocolors](https://github.com/sindresorhus/yoctocolors) for a smaller alternative
|
||||
|
||||
## Highlights
|
||||
|
||||
- Expressive API
|
||||
- Highly performant
|
||||
- No dependencies
|
||||
- Ability to nest styles
|
||||
- [256/Truecolor color support](#256-and-truecolor-color-support)
|
||||
- Auto-detects color support
|
||||
- Doesn't extend `String.prototype`
|
||||
- Clean and focused
|
||||
- Actively maintained
|
||||
- [Used by ~17,000 packages](https://www.npmjs.com/browse/depended/chalk) as of June 20th, 2017
|
||||
|
||||
- [Used by ~115,000 packages](https://www.npmjs.com/browse/depended/chalk) as of July 4, 2024
|
||||
|
||||
## Install
|
||||
|
||||
```console
|
||||
$ npm install chalk
|
||||
```sh
|
||||
npm install chalk
|
||||
```
|
||||
|
||||
**IMPORTANT:** Chalk 5 is ESM. If you want to use Chalk with TypeScript or a build tool, you will probably want to use Chalk 4 for now. [Read more.](https://github.com/chalk/chalk/releases/tag/v5.0.0)
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const chalk = require('chalk');
|
||||
import chalk from 'chalk';
|
||||
|
||||
console.log(chalk.blue('Hello world!'));
|
||||
```
|
||||
|
|
@ -47,11 +52,12 @@ console.log(chalk.blue('Hello world!'));
|
|||
Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
|
||||
|
||||
```js
|
||||
const chalk = require('chalk');
|
||||
import chalk from 'chalk';
|
||||
|
||||
const log = console.log;
|
||||
|
||||
// Combine styled and normal strings
|
||||
log(chalk.blue('Hello') + 'World' + chalk.red('!'));
|
||||
log(chalk.blue('Hello') + ' World' + chalk.red('!'));
|
||||
|
||||
// Compose multiple styles using the chainable API
|
||||
log(chalk.blue.bgRed.bold('Hello world!'));
|
||||
|
|
@ -76,15 +82,7 @@ RAM: ${chalk.green('40%')}
|
|||
DISK: ${chalk.yellow('70%')}
|
||||
`);
|
||||
|
||||
// ES2015 tagged template literal
|
||||
log(chalk`
|
||||
CPU: {red ${cpu.totalPercent}%}
|
||||
RAM: {green ${ram.used / ram.total * 100}%}
|
||||
DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
|
||||
`);
|
||||
|
||||
// Use RGB colors in terminal emulators that support it.
|
||||
log(chalk.keyword('orange')('Yay for orange colored text!'));
|
||||
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
|
||||
log(chalk.hex('#DEADED').bold('Bold gray!'));
|
||||
```
|
||||
|
|
@ -92,10 +90,10 @@ log(chalk.hex('#DEADED').bold('Bold gray!'));
|
|||
Easily define your own themes:
|
||||
|
||||
```js
|
||||
const chalk = require('chalk');
|
||||
import chalk from 'chalk';
|
||||
|
||||
const error = chalk.bold.red;
|
||||
const warning = chalk.keyword('orange');
|
||||
const warning = chalk.hex('#FFA500'); // Orange color
|
||||
|
||||
console.log(error('Error!'));
|
||||
console.log(warning('Warning!'));
|
||||
|
|
@ -104,12 +102,13 @@ console.log(warning('Warning!'));
|
|||
Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args):
|
||||
|
||||
```js
|
||||
import chalk from 'chalk';
|
||||
|
||||
const name = 'Sindre';
|
||||
console.log(chalk.green('Hello %s'), name);
|
||||
//=> 'Hello Sindre'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### chalk.`<style>[.<style>...](string, [string...])`
|
||||
|
|
@ -120,57 +119,69 @@ Chain [styles](#styles) and call the last one as a method with a string argument
|
|||
|
||||
Multiple arguments will be separated by space.
|
||||
|
||||
### chalk.enabled
|
||||
|
||||
Color support is automatically detected, as is the level (see `chalk.level`). However, if you'd like to simply enable/disable Chalk, you can do so via the `.enabled` property.
|
||||
|
||||
Chalk is enabled by default unless expicitly disabled via the constructor or `chalk.level` is `0`.
|
||||
|
||||
If you need to change this in a reusable module, create a new instance:
|
||||
|
||||
```js
|
||||
const ctx = new chalk.constructor({enabled: false});
|
||||
```
|
||||
|
||||
### chalk.level
|
||||
|
||||
Specifies the level of color support.
|
||||
|
||||
Color support is automatically detected, but you can override it by setting the `level` property. You should however only do this in your own code as it applies globally to all Chalk consumers.
|
||||
|
||||
If you need to change this in a reusable module, create a new instance:
|
||||
|
||||
```js
|
||||
const ctx = new chalk.constructor({level: 0});
|
||||
import {Chalk} from 'chalk';
|
||||
|
||||
const customChalk = new Chalk({level: 0});
|
||||
```
|
||||
|
||||
Levels are as follows:
|
||||
| Level | Description |
|
||||
| :---: | :--- |
|
||||
| `0` | All colors disabled |
|
||||
| `1` | Basic color support (16 colors) |
|
||||
| `2` | 256 color support |
|
||||
| `3` | Truecolor support (16 million colors) |
|
||||
|
||||
0. All colors disabled
|
||||
1. Basic color support (16 colors)
|
||||
2. 256 color support
|
||||
3. Truecolor support (16 million colors)
|
||||
|
||||
### chalk.supportsColor
|
||||
### supportsColor
|
||||
|
||||
Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
|
||||
|
||||
Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add the environment variable `FORCE_COLOR=1` to forcefully enable color or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
|
||||
Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
|
||||
|
||||
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
|
||||
|
||||
### chalkStderr and supportsColorStderr
|
||||
|
||||
`chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `supportsColorStderr` is exposed for convenience.
|
||||
|
||||
### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames
|
||||
|
||||
All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.
|
||||
|
||||
This can be useful if you wrap Chalk and need to validate input:
|
||||
|
||||
```js
|
||||
import {modifierNames, foregroundColorNames} from 'chalk';
|
||||
|
||||
console.log(modifierNames.includes('bold'));
|
||||
//=> true
|
||||
|
||||
console.log(foregroundColorNames.includes('pink'));
|
||||
//=> false
|
||||
```
|
||||
|
||||
## Styles
|
||||
|
||||
### Modifiers
|
||||
|
||||
- `reset`
|
||||
- `bold`
|
||||
- `dim`
|
||||
- `italic` *(Not widely supported)*
|
||||
- `underline`
|
||||
- `inverse`
|
||||
- `hidden`
|
||||
- `strikethrough` *(Not widely supported)*
|
||||
- `visible` (Text is emitted only if enabled)
|
||||
- `reset` - Reset the current style.
|
||||
- `bold` - Make the text bold.
|
||||
- `dim` - Make the text have lower opacity.
|
||||
- `italic` - Make the text italic. *(Not widely supported)*
|
||||
- `underline` - Put a horizontal line below the text. *(Not widely supported)*
|
||||
- `overline` - Put a horizontal line above the text. *(Not widely supported)*
|
||||
- `inverse` - Invert background and foreground colors.
|
||||
- `hidden` - Print the text but make it invisible.
|
||||
- `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*
|
||||
- `visible` - Print the text only when Chalk has a color level above zero. Can be useful for things that are purely cosmetic.
|
||||
|
||||
### Colors
|
||||
|
||||
|
|
@ -178,11 +189,11 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
|
|||
- `red`
|
||||
- `green`
|
||||
- `yellow`
|
||||
- `blue` *(On Windows the bright version is used since normal blue is illegible)*
|
||||
- `blue`
|
||||
- `magenta`
|
||||
- `cyan`
|
||||
- `white`
|
||||
- `gray` ("bright black")
|
||||
- `blackBright` (alias: `gray`, `grey`)
|
||||
- `redBright`
|
||||
- `greenBright`
|
||||
- `yellowBright`
|
||||
|
|
@ -201,7 +212,7 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
|
|||
- `bgMagenta`
|
||||
- `bgCyan`
|
||||
- `bgWhite`
|
||||
- `bgBlackBright`
|
||||
- `bgBlackBright` (alias: `bgGray`, `bgGrey`)
|
||||
- `bgRedBright`
|
||||
- `bgGreenBright`
|
||||
- `bgYellowBright`
|
||||
|
|
@ -210,79 +221,59 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
|
|||
- `bgCyanBright`
|
||||
- `bgWhiteBright`
|
||||
|
||||
|
||||
## Tagged template literal
|
||||
|
||||
Chalk can be used as a [tagged template literal](http://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
|
||||
|
||||
```js
|
||||
const chalk = require('chalk');
|
||||
|
||||
const miles = 18;
|
||||
const calculateFeet = miles => miles * 5280;
|
||||
|
||||
console.log(chalk`
|
||||
There are {bold 5280 feet} in a mile.
|
||||
In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.
|
||||
`);
|
||||
```
|
||||
|
||||
Blocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).
|
||||
|
||||
Template styles are chained exactly like normal Chalk styles. The following two statements are equivalent:
|
||||
|
||||
```js
|
||||
console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
|
||||
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
|
||||
```
|
||||
|
||||
Note that function styles (`rgb()`, `hsl()`, `keyword()`, etc.) may not contain spaces between parameters.
|
||||
|
||||
All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
|
||||
|
||||
|
||||
## 256 and Truecolor color support
|
||||
|
||||
Chalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.
|
||||
Chalk supports 256 colors and [Truecolor](https://github.com/termstandard/colors) (16 million colors) on supported terminal apps.
|
||||
|
||||
Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying `{level: n}` as a Chalk option). For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).
|
||||
|
||||
Examples:
|
||||
|
||||
- `chalk.hex('#DEADED').underline('Hello, world!')`
|
||||
- `chalk.keyword('orange')('Some orange text')`
|
||||
- `chalk.rgb(15, 100, 204).inverse('Hello!')`
|
||||
|
||||
Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `keyword` for foreground colors and `bgKeyword` for background colors).
|
||||
Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `hex` for foreground colors and `bgHex` for background colors).
|
||||
|
||||
- `chalk.bgHex('#DEADED').underline('Hello, world!')`
|
||||
- `chalk.bgKeyword('orange')('Some orange text')`
|
||||
- `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
|
||||
|
||||
The following color models can be used:
|
||||
|
||||
- [`rgb`](https://en.wikipedia.org/wiki/RGB_color_model) - Example: `chalk.rgb(255, 136, 0).bold('Orange!')`
|
||||
- [`hex`](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) - Example: `chalk.hex('#FF8800').bold('Orange!')`
|
||||
- [`keyword`](https://www.w3.org/wiki/CSS/Properties/color/keywords) (CSS keywords) - Example: `chalk.keyword('orange').bold('Orange!')`
|
||||
- [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')`
|
||||
- [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 1, 1).bold('Orange!')`
|
||||
- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hsl(32, 0, 50).bold('Orange!')`
|
||||
- `ansi16`
|
||||
- `ansi256`
|
||||
- [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`
|
||||
|
||||
## Browser support
|
||||
|
||||
Since Chrome 69, ANSI escape codes are natively supported in the developer console.
|
||||
|
||||
## Windows
|
||||
|
||||
If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) instead of `cmd.exe`.
|
||||
If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.
|
||||
|
||||
## FAQ
|
||||
|
||||
## Origin story
|
||||
### Why not switch to a smaller coloring package?
|
||||
|
||||
[colors.js](https://github.com/Marak/colors.js) used to be the most popular string styling module, but it has serious deficiencies like extending `String.prototype` which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68) and the package is unmaintained. Although there are other packages, they either do too much or not enough. Chalk is a clean and focused alternative.
|
||||
Chalk may be larger, but there is a reason for that. It offers a more user-friendly API, well-documented types, supports millions of colors, and covers edge cases that smaller alternatives miss. Chalk is mature, reliable, and built to last.
|
||||
|
||||
But beyond the technical aspects, there's something more critical: trust and long-term maintenance. I have been active in open source for over a decade, and I'm committed to keeping Chalk maintained. Smaller packages might seem appealing now, but there's no guarantee they will be around for the long term, or that they won't become malicious over time.
|
||||
|
||||
Chalk is also likely already in your dependency tree (since 100K+ packages depend on it), so switching won’t save space—in fact, it might increase it. npm deduplicates dependencies, so multiple Chalk instances turn into one, but adding another package alongside it will increase your overall size.
|
||||
|
||||
If the goal is to clean up the ecosystem, switching away from Chalk won’t even make a dent. The real problem lies with packages that have very deep dependency trees (for example, those including a lot of polyfills). Chalk has no dependencies. It's better to focus on impactful changes rather than minor optimizations.
|
||||
|
||||
If absolute package size is important to you, I also maintain [yoctocolors](https://github.com/sindresorhus/yoctocolors), one of the smallest color packages out there.
|
||||
|
||||
*\- [Sindre](https://github.com/sindresorhus)*
|
||||
|
||||
### But the smaller coloring package has benchmarks showing it is faster
|
||||
|
||||
[Micro-benchmarks are flawed](https://sindresorhus.com/blog/micro-benchmark-fallacy) because they measure performance in unrealistic, isolated scenarios, often giving a distorted view of real-world performance. Don't believe marketing fluff. All the coloring packages are more than fast enough.
|
||||
|
||||
## Related
|
||||
|
||||
- [chalk-template](https://github.com/chalk/chalk-template) - [Tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) support for this module
|
||||
- [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
|
||||
- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
|
||||
- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
|
||||
|
|
@ -296,14 +287,11 @@ If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) i
|
|||
- [chalk-animation](https://github.com/bokub/chalk-animation) - Animate strings in the terminal
|
||||
- [gradient-string](https://github.com/bokub/gradient-string) - Apply color gradients to strings
|
||||
- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
|
||||
- [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal
|
||||
|
||||
*(Not accepting additional entries)*
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Josh Junon](https://github.com/qix-)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
|
|
|||
325
source/index.d.ts
vendored
Normal file
325
source/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,325 @@
|
|||
// TODO: Make it this when TS suports that.
|
||||
// import {ModifierName, ForegroundColor, BackgroundColor, ColorName} from '#ansi-styles';
|
||||
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
|
||||
import {
|
||||
ModifierName,
|
||||
ForegroundColorName,
|
||||
BackgroundColorName,
|
||||
ColorName,
|
||||
} from './vendor/ansi-styles/index.js';
|
||||
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
Specify the color support for Chalk.
|
||||
|
||||
By default, color support is automatically detected based on the environment.
|
||||
|
||||
Levels:
|
||||
- `0` - All colors disabled.
|
||||
- `1` - Basic 16 colors support.
|
||||
- `2` - ANSI 256 colors support.
|
||||
- `3` - Truecolor 16 million colors support.
|
||||
*/
|
||||
readonly level?: ColorSupportLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
Return a new Chalk instance.
|
||||
*/
|
||||
export const Chalk: new (options?: Options) => ChalkInstance; // eslint-disable-line @typescript-eslint/naming-convention
|
||||
|
||||
export interface ChalkInstance {
|
||||
(...text: unknown[]): string;
|
||||
|
||||
/**
|
||||
The color support for Chalk.
|
||||
|
||||
By default, color support is automatically detected based on the environment.
|
||||
|
||||
Levels:
|
||||
- `0` - All colors disabled.
|
||||
- `1` - Basic 16 colors support.
|
||||
- `2` - ANSI 256 colors support.
|
||||
- `3` - Truecolor 16 million colors support.
|
||||
*/
|
||||
level: ColorSupportLevel;
|
||||
|
||||
/**
|
||||
Use RGB values to set text color.
|
||||
|
||||
@example
|
||||
```
|
||||
import chalk from 'chalk';
|
||||
|
||||
chalk.rgb(222, 173, 237);
|
||||
```
|
||||
*/
|
||||
rgb: (red: number, green: number, blue: number) => this;
|
||||
|
||||
/**
|
||||
Use HEX value to set text color.
|
||||
|
||||
@param color - Hexadecimal value representing the desired color.
|
||||
|
||||
@example
|
||||
```
|
||||
import chalk from 'chalk';
|
||||
|
||||
chalk.hex('#DEADED');
|
||||
```
|
||||
*/
|
||||
hex: (color: string) => this;
|
||||
|
||||
/**
|
||||
Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
|
||||
|
||||
@example
|
||||
```
|
||||
import chalk from 'chalk';
|
||||
|
||||
chalk.ansi256(201);
|
||||
```
|
||||
*/
|
||||
ansi256: (index: number) => this;
|
||||
|
||||
/**
|
||||
Use RGB values to set background color.
|
||||
|
||||
@example
|
||||
```
|
||||
import chalk from 'chalk';
|
||||
|
||||
chalk.bgRgb(222, 173, 237);
|
||||
```
|
||||
*/
|
||||
bgRgb: (red: number, green: number, blue: number) => this;
|
||||
|
||||
/**
|
||||
Use HEX value to set background color.
|
||||
|
||||
@param color - Hexadecimal value representing the desired color.
|
||||
|
||||
@example
|
||||
```
|
||||
import chalk from 'chalk';
|
||||
|
||||
chalk.bgHex('#DEADED');
|
||||
```
|
||||
*/
|
||||
bgHex: (color: string) => this;
|
||||
|
||||
/**
|
||||
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
|
||||
|
||||
@example
|
||||
```
|
||||
import chalk from 'chalk';
|
||||
|
||||
chalk.bgAnsi256(201);
|
||||
```
|
||||
*/
|
||||
bgAnsi256: (index: number) => this;
|
||||
|
||||
/**
|
||||
Modifier: Reset the current style.
|
||||
*/
|
||||
readonly reset: this;
|
||||
|
||||
/**
|
||||
Modifier: Make the text bold.
|
||||
*/
|
||||
readonly bold: this;
|
||||
|
||||
/**
|
||||
Modifier: Make the text have lower opacity.
|
||||
*/
|
||||
readonly dim: this;
|
||||
|
||||
/**
|
||||
Modifier: Make the text italic. *(Not widely supported)*
|
||||
*/
|
||||
readonly italic: this;
|
||||
|
||||
/**
|
||||
Modifier: Put a horizontal line below the text. *(Not widely supported)*
|
||||
*/
|
||||
readonly underline: this;
|
||||
|
||||
/**
|
||||
Modifier: Put a horizontal line above the text. *(Not widely supported)*
|
||||
*/
|
||||
readonly overline: this;
|
||||
|
||||
/**
|
||||
Modifier: Invert background and foreground colors.
|
||||
*/
|
||||
readonly inverse: this;
|
||||
|
||||
/**
|
||||
Modifier: Print the text but make it invisible.
|
||||
*/
|
||||
readonly hidden: this;
|
||||
|
||||
/**
|
||||
Modifier: Puts a horizontal line through the center of the text. *(Not widely supported)*
|
||||
*/
|
||||
readonly strikethrough: this;
|
||||
|
||||
/**
|
||||
Modifier: Print the text only when Chalk has a color level above zero.
|
||||
|
||||
Can be useful for things that are purely cosmetic.
|
||||
*/
|
||||
readonly visible: this;
|
||||
|
||||
readonly black: this;
|
||||
readonly red: this;
|
||||
readonly green: this;
|
||||
readonly yellow: this;
|
||||
readonly blue: this;
|
||||
readonly magenta: this;
|
||||
readonly cyan: this;
|
||||
readonly white: this;
|
||||
|
||||
/*
|
||||
Alias for `blackBright`.
|
||||
*/
|
||||
readonly gray: this;
|
||||
|
||||
/*
|
||||
Alias for `blackBright`.
|
||||
*/
|
||||
readonly grey: this;
|
||||
|
||||
readonly blackBright: this;
|
||||
readonly redBright: this;
|
||||
readonly greenBright: this;
|
||||
readonly yellowBright: this;
|
||||
readonly blueBright: this;
|
||||
readonly magentaBright: this;
|
||||
readonly cyanBright: this;
|
||||
readonly whiteBright: this;
|
||||
|
||||
readonly bgBlack: this;
|
||||
readonly bgRed: this;
|
||||
readonly bgGreen: this;
|
||||
readonly bgYellow: this;
|
||||
readonly bgBlue: this;
|
||||
readonly bgMagenta: this;
|
||||
readonly bgCyan: this;
|
||||
readonly bgWhite: this;
|
||||
|
||||
/*
|
||||
Alias for `bgBlackBright`.
|
||||
*/
|
||||
readonly bgGray: this;
|
||||
|
||||
/*
|
||||
Alias for `bgBlackBright`.
|
||||
*/
|
||||
readonly bgGrey: this;
|
||||
|
||||
readonly bgBlackBright: this;
|
||||
readonly bgRedBright: this;
|
||||
readonly bgGreenBright: this;
|
||||
readonly bgYellowBright: this;
|
||||
readonly bgBlueBright: this;
|
||||
readonly bgMagentaBright: this;
|
||||
readonly bgCyanBright: this;
|
||||
readonly bgWhiteBright: this;
|
||||
}
|
||||
|
||||
/**
|
||||
Main Chalk object that allows to chain styles together.
|
||||
|
||||
Call the last one as a method with a string argument.
|
||||
|
||||
Order doesn't matter, and later styles take precedent in case of a conflict.
|
||||
|
||||
This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
|
||||
*/
|
||||
declare const chalk: ChalkInstance;
|
||||
|
||||
export const supportsColor: ColorInfo;
|
||||
|
||||
export const chalkStderr: typeof chalk;
|
||||
export const supportsColorStderr: typeof supportsColor;
|
||||
|
||||
export {
|
||||
ModifierName, ForegroundColorName, BackgroundColorName, ColorName,
|
||||
modifierNames, foregroundColorNames, backgroundColorNames, colorNames,
|
||||
// } from '#ansi-styles';
|
||||
} from './vendor/ansi-styles/index.js';
|
||||
|
||||
export {
|
||||
ColorInfo,
|
||||
ColorSupport,
|
||||
ColorSupportLevel,
|
||||
// } from '#supports-color';
|
||||
} from './vendor/supports-color/index.js';
|
||||
|
||||
// TODO: Remove these aliases in the next major version
|
||||
/**
|
||||
@deprecated Use `ModifierName` instead.
|
||||
|
||||
Basic modifier names.
|
||||
*/
|
||||
export type Modifiers = ModifierName;
|
||||
|
||||
/**
|
||||
@deprecated Use `ForegroundColorName` instead.
|
||||
|
||||
Basic foreground color names.
|
||||
|
||||
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
||||
*/
|
||||
export type ForegroundColor = ForegroundColorName;
|
||||
|
||||
/**
|
||||
@deprecated Use `BackgroundColorName` instead.
|
||||
|
||||
Basic background color names.
|
||||
|
||||
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
||||
*/
|
||||
export type BackgroundColor = BackgroundColorName;
|
||||
|
||||
/**
|
||||
@deprecated Use `ColorName` instead.
|
||||
|
||||
Basic color names. The combination of foreground and background color names.
|
||||
|
||||
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
||||
*/
|
||||
export type Color = ColorName;
|
||||
|
||||
/**
|
||||
@deprecated Use `modifierNames` instead.
|
||||
|
||||
Basic modifier names.
|
||||
*/
|
||||
export const modifiers: readonly Modifiers[];
|
||||
|
||||
/**
|
||||
@deprecated Use `foregroundColorNames` instead.
|
||||
|
||||
Basic foreground color names.
|
||||
*/
|
||||
export const foregroundColors: readonly ForegroundColor[];
|
||||
|
||||
/**
|
||||
@deprecated Use `backgroundColorNames` instead.
|
||||
|
||||
Basic background color names.
|
||||
*/
|
||||
export const backgroundColors: readonly BackgroundColor[];
|
||||
|
||||
/**
|
||||
@deprecated Use `colorNames` instead.
|
||||
|
||||
Basic color names. The combination of foreground and background color names.
|
||||
*/
|
||||
export const colors: readonly Color[];
|
||||
|
||||
export default chalk;
|
||||
225
source/index.js
Normal file
225
source/index.js
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
import ansiStyles from '#ansi-styles';
|
||||
import supportsColor from '#supports-color';
|
||||
import { // eslint-disable-line import/order
|
||||
stringReplaceAll,
|
||||
stringEncaseCRLFWithFirstIndex,
|
||||
} from './utilities.js';
|
||||
|
||||
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
|
||||
|
||||
const GENERATOR = Symbol('GENERATOR');
|
||||
const STYLER = Symbol('STYLER');
|
||||
const IS_EMPTY = Symbol('IS_EMPTY');
|
||||
|
||||
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
||||
const levelMapping = [
|
||||
'ansi',
|
||||
'ansi',
|
||||
'ansi256',
|
||||
'ansi16m',
|
||||
];
|
||||
|
||||
const styles = Object.create(null);
|
||||
|
||||
const applyOptions = (object, options = {}) => {
|
||||
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
||||
throw new Error('The `level` option should be an integer from 0 to 3');
|
||||
}
|
||||
|
||||
// Detect level if not set manually
|
||||
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
||||
object.level = options.level === undefined ? colorLevel : options.level;
|
||||
};
|
||||
|
||||
export class Chalk {
|
||||
constructor(options) {
|
||||
// eslint-disable-next-line no-constructor-return
|
||||
return chalkFactory(options);
|
||||
}
|
||||
}
|
||||
|
||||
const chalkFactory = options => {
|
||||
const chalk = (...strings) => strings.join(' ');
|
||||
applyOptions(chalk, options);
|
||||
|
||||
Object.setPrototypeOf(chalk, createChalk.prototype);
|
||||
|
||||
return chalk;
|
||||
};
|
||||
|
||||
function createChalk(options) {
|
||||
return chalkFactory(options);
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
||||
|
||||
for (const [styleName, style] of Object.entries(ansiStyles)) {
|
||||
styles[styleName] = {
|
||||
get() {
|
||||
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
||||
Object.defineProperty(this, styleName, {value: builder});
|
||||
return builder;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
styles.visible = {
|
||||
get() {
|
||||
const builder = createBuilder(this, this[STYLER], true);
|
||||
Object.defineProperty(this, 'visible', {value: builder});
|
||||
return builder;
|
||||
},
|
||||
};
|
||||
|
||||
const getModelAnsi = (model, level, type, ...arguments_) => {
|
||||
if (model === 'rgb') {
|
||||
if (level === 'ansi16m') {
|
||||
return ansiStyles[type].ansi16m(...arguments_);
|
||||
}
|
||||
|
||||
if (level === 'ansi256') {
|
||||
return ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));
|
||||
}
|
||||
|
||||
return ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));
|
||||
}
|
||||
|
||||
if (model === 'hex') {
|
||||
return getModelAnsi('rgb', level, type, ...ansiStyles.hexToRgb(...arguments_));
|
||||
}
|
||||
|
||||
return ansiStyles[type][model](...arguments_);
|
||||
};
|
||||
|
||||
const usedModels = ['rgb', 'hex', 'ansi256'];
|
||||
|
||||
for (const model of usedModels) {
|
||||
styles[model] = {
|
||||
get() {
|
||||
const {level} = this;
|
||||
return function (...arguments_) {
|
||||
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]);
|
||||
return createBuilder(this, styler, this[IS_EMPTY]);
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
||||
styles[bgModel] = {
|
||||
get() {
|
||||
const {level} = this;
|
||||
return function (...arguments_) {
|
||||
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]);
|
||||
return createBuilder(this, styler, this[IS_EMPTY]);
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const proto = Object.defineProperties(() => {}, {
|
||||
...styles,
|
||||
level: {
|
||||
enumerable: true,
|
||||
get() {
|
||||
return this[GENERATOR].level;
|
||||
},
|
||||
set(level) {
|
||||
this[GENERATOR].level = level;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createStyler = (open, close, parent) => {
|
||||
let openAll;
|
||||
let closeAll;
|
||||
if (parent === undefined) {
|
||||
openAll = open;
|
||||
closeAll = close;
|
||||
} else {
|
||||
openAll = parent.openAll + open;
|
||||
closeAll = close + parent.closeAll;
|
||||
}
|
||||
|
||||
return {
|
||||
open,
|
||||
close,
|
||||
openAll,
|
||||
closeAll,
|
||||
parent,
|
||||
};
|
||||
};
|
||||
|
||||
const createBuilder = (self, _styler, _isEmpty) => {
|
||||
// Single argument is hot path, implicit coercion is faster than anything
|
||||
// eslint-disable-next-line no-implicit-coercion
|
||||
const builder = (...arguments_) => applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
|
||||
|
||||
// We alter the prototype because we must return a function, but there is
|
||||
// no way to create a function with a different prototype
|
||||
Object.setPrototypeOf(builder, proto);
|
||||
|
||||
builder[GENERATOR] = self;
|
||||
builder[STYLER] = _styler;
|
||||
builder[IS_EMPTY] = _isEmpty;
|
||||
|
||||
return builder;
|
||||
};
|
||||
|
||||
const applyStyle = (self, string) => {
|
||||
if (self.level <= 0 || !string) {
|
||||
return self[IS_EMPTY] ? '' : string;
|
||||
}
|
||||
|
||||
let styler = self[STYLER];
|
||||
|
||||
if (styler === undefined) {
|
||||
return string;
|
||||
}
|
||||
|
||||
const {openAll, closeAll} = styler;
|
||||
if (string.includes('\u001B')) {
|
||||
while (styler !== undefined) {
|
||||
// Replace any instances already present with a re-opening code
|
||||
// otherwise only the part of the string until said closing code
|
||||
// will be colored, and the rest will simply be 'plain'.
|
||||
string = stringReplaceAll(string, styler.close, styler.open);
|
||||
|
||||
styler = styler.parent;
|
||||
}
|
||||
}
|
||||
|
||||
// We can move both next actions out of loop, because remaining actions in loop won't have
|
||||
// any/visible effect on parts we add here. Close the styling before a linebreak and reopen
|
||||
// after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
|
||||
const lfIndex = string.indexOf('\n');
|
||||
if (lfIndex !== -1) {
|
||||
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
||||
}
|
||||
|
||||
return openAll + string + closeAll;
|
||||
};
|
||||
|
||||
Object.defineProperties(createChalk.prototype, styles);
|
||||
|
||||
const chalk = createChalk();
|
||||
export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});
|
||||
|
||||
export {
|
||||
modifierNames,
|
||||
foregroundColorNames,
|
||||
backgroundColorNames,
|
||||
colorNames,
|
||||
|
||||
// TODO: Remove these aliases in the next major version
|
||||
modifierNames as modifiers,
|
||||
foregroundColorNames as foregroundColors,
|
||||
backgroundColorNames as backgroundColors,
|
||||
colorNames as colors,
|
||||
} from './vendor/ansi-styles/index.js';
|
||||
|
||||
export {
|
||||
stdoutColor as supportsColor,
|
||||
stderrColor as supportsColorStderr,
|
||||
};
|
||||
|
||||
export default chalk;
|
||||
179
source/index.test-d.ts
Normal file
179
source/index.test-d.ts
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
import {
|
||||
expectType,
|
||||
expectAssignable,
|
||||
expectError,
|
||||
expectDeprecated,
|
||||
} from 'tsd';
|
||||
import chalk, {
|
||||
Chalk,
|
||||
ChalkInstance,
|
||||
ColorInfo,
|
||||
ColorSupport,
|
||||
ColorSupportLevel,
|
||||
chalkStderr,
|
||||
supportsColor,
|
||||
supportsColorStderr,
|
||||
ModifierName,
|
||||
ForegroundColorName,
|
||||
BackgroundColorName,
|
||||
ColorName,
|
||||
Modifiers,
|
||||
} from './index.js';
|
||||
|
||||
// - supportsColor -
|
||||
expectType<ColorInfo>(supportsColor);
|
||||
if (supportsColor) {
|
||||
expectType<ColorSupport>(supportsColor);
|
||||
expectType<ColorSupportLevel>(supportsColor.level);
|
||||
expectType<boolean>(supportsColor.hasBasic);
|
||||
expectType<boolean>(supportsColor.has256);
|
||||
expectType<boolean>(supportsColor.has16m);
|
||||
}
|
||||
|
||||
// - stderr -
|
||||
expectAssignable<ChalkInstance>(chalkStderr);
|
||||
expectType<ColorInfo>(supportsColorStderr);
|
||||
if (supportsColorStderr) {
|
||||
expectType<boolean>(supportsColorStderr.hasBasic);
|
||||
expectType<boolean>(supportsColorStderr.has256);
|
||||
expectType<boolean>(supportsColorStderr.has16m);
|
||||
}
|
||||
|
||||
// -- `supportsColorStderr` is not a member of the Chalk interface --
|
||||
expectError(chalk.reset.supportsColorStderr);
|
||||
|
||||
// -- `supportsColor` is not a member of the Chalk interface --
|
||||
expectError(chalk.reset.supportsColor);
|
||||
|
||||
// - Chalk -
|
||||
// -- Instance --
|
||||
expectType<ChalkInstance>(new Chalk({level: 1}));
|
||||
|
||||
// -- Properties --
|
||||
expectType<ColorSupportLevel>(chalk.level);
|
||||
|
||||
// -- Color methods --
|
||||
expectType<ChalkInstance>(chalk.rgb(0, 0, 0));
|
||||
expectType<ChalkInstance>(chalk.hex('#DEADED'));
|
||||
expectType<ChalkInstance>(chalk.ansi256(0));
|
||||
expectType<ChalkInstance>(chalk.bgRgb(0, 0, 0));
|
||||
expectType<ChalkInstance>(chalk.bgHex('#DEADED'));
|
||||
expectType<ChalkInstance>(chalk.bgAnsi256(0));
|
||||
|
||||
// -- Modifiers --
|
||||
expectType<string>(chalk.reset('foo'));
|
||||
expectType<string>(chalk.bold('foo'));
|
||||
expectType<string>(chalk.dim('foo'));
|
||||
expectType<string>(chalk.italic('foo'));
|
||||
expectType<string>(chalk.underline('foo'));
|
||||
expectType<string>(chalk.overline('foo'));
|
||||
expectType<string>(chalk.inverse('foo'));
|
||||
expectType<string>(chalk.hidden('foo'));
|
||||
expectType<string>(chalk.strikethrough('foo'));
|
||||
expectType<string>(chalk.visible('foo'));
|
||||
expectType<string>(chalk.reset`foo`);
|
||||
expectType<string>(chalk.bold`foo`);
|
||||
expectType<string>(chalk.dim`foo`);
|
||||
expectType<string>(chalk.italic`foo`);
|
||||
expectType<string>(chalk.underline`foo`);
|
||||
expectType<string>(chalk.inverse`foo`);
|
||||
expectType<string>(chalk.hidden`foo`);
|
||||
expectType<string>(chalk.strikethrough`foo`);
|
||||
expectType<string>(chalk.visible`foo`);
|
||||
|
||||
// -- Colors --
|
||||
expectType<string>(chalk.black('foo'));
|
||||
expectType<string>(chalk.red('foo'));
|
||||
expectType<string>(chalk.green('foo'));
|
||||
expectType<string>(chalk.yellow('foo'));
|
||||
expectType<string>(chalk.blue('foo'));
|
||||
expectType<string>(chalk.magenta('foo'));
|
||||
expectType<string>(chalk.cyan('foo'));
|
||||
expectType<string>(chalk.white('foo'));
|
||||
expectType<string>(chalk.gray('foo'));
|
||||
expectType<string>(chalk.grey('foo'));
|
||||
expectType<string>(chalk.blackBright('foo'));
|
||||
expectType<string>(chalk.redBright('foo'));
|
||||
expectType<string>(chalk.greenBright('foo'));
|
||||
expectType<string>(chalk.yellowBright('foo'));
|
||||
expectType<string>(chalk.blueBright('foo'));
|
||||
expectType<string>(chalk.magentaBright('foo'));
|
||||
expectType<string>(chalk.cyanBright('foo'));
|
||||
expectType<string>(chalk.whiteBright('foo'));
|
||||
expectType<string>(chalk.bgBlack('foo'));
|
||||
expectType<string>(chalk.bgRed('foo'));
|
||||
expectType<string>(chalk.bgGreen('foo'));
|
||||
expectType<string>(chalk.bgYellow('foo'));
|
||||
expectType<string>(chalk.bgBlue('foo'));
|
||||
expectType<string>(chalk.bgMagenta('foo'));
|
||||
expectType<string>(chalk.bgCyan('foo'));
|
||||
expectType<string>(chalk.bgWhite('foo'));
|
||||
expectType<string>(chalk.bgBlackBright('foo'));
|
||||
expectType<string>(chalk.bgRedBright('foo'));
|
||||
expectType<string>(chalk.bgGreenBright('foo'));
|
||||
expectType<string>(chalk.bgYellowBright('foo'));
|
||||
expectType<string>(chalk.bgBlueBright('foo'));
|
||||
expectType<string>(chalk.bgMagentaBright('foo'));
|
||||
expectType<string>(chalk.bgCyanBright('foo'));
|
||||
expectType<string>(chalk.bgWhiteBright('foo'));
|
||||
expectType<string>(chalk.black`foo`);
|
||||
expectType<string>(chalk.red`foo`);
|
||||
expectType<string>(chalk.green`foo`);
|
||||
expectType<string>(chalk.yellow`foo`);
|
||||
expectType<string>(chalk.blue`foo`);
|
||||
expectType<string>(chalk.magenta`foo`);
|
||||
expectType<string>(chalk.cyan`foo`);
|
||||
expectType<string>(chalk.white`foo`);
|
||||
expectType<string>(chalk.gray`foo`);
|
||||
expectType<string>(chalk.grey`foo`);
|
||||
expectType<string>(chalk.blackBright`foo`);
|
||||
expectType<string>(chalk.redBright`foo`);
|
||||
expectType<string>(chalk.greenBright`foo`);
|
||||
expectType<string>(chalk.yellowBright`foo`);
|
||||
expectType<string>(chalk.blueBright`foo`);
|
||||
expectType<string>(chalk.magentaBright`foo`);
|
||||
expectType<string>(chalk.cyanBright`foo`);
|
||||
expectType<string>(chalk.whiteBright`foo`);
|
||||
expectType<string>(chalk.bgBlack`foo`);
|
||||
expectType<string>(chalk.bgRed`foo`);
|
||||
expectType<string>(chalk.bgGreen`foo`);
|
||||
expectType<string>(chalk.bgYellow`foo`);
|
||||
expectType<string>(chalk.bgBlue`foo`);
|
||||
expectType<string>(chalk.bgMagenta`foo`);
|
||||
expectType<string>(chalk.bgCyan`foo`);
|
||||
expectType<string>(chalk.bgWhite`foo`);
|
||||
expectType<string>(chalk.bgBlackBright`foo`);
|
||||
expectType<string>(chalk.bgRedBright`foo`);
|
||||
expectType<string>(chalk.bgGreenBright`foo`);
|
||||
expectType<string>(chalk.bgYellowBright`foo`);
|
||||
expectType<string>(chalk.bgBlueBright`foo`);
|
||||
expectType<string>(chalk.bgMagentaBright`foo`);
|
||||
expectType<string>(chalk.bgCyanBright`foo`);
|
||||
expectType<string>(chalk.bgWhiteBright`foo`);
|
||||
|
||||
// -- Complex --
|
||||
expectType<string>(chalk.red.bgGreen.underline('foo'));
|
||||
expectType<string>(chalk.underline.red.bgGreen('foo'));
|
||||
|
||||
// -- Complex template literal --
|
||||
expectType<string>(chalk.underline``);
|
||||
expectType<string>(chalk.red.bgGreen.bold`Hello {italic.blue ${name}}`);
|
||||
expectType<string>(chalk.strikethrough.cyanBright.bgBlack`Works with {reset {bold numbers}} {bold.red ${1}}`);
|
||||
|
||||
// -- Modifiers types
|
||||
expectAssignable<ModifierName>('strikethrough');
|
||||
expectError<ModifierName>('delete');
|
||||
|
||||
// -- Foreground types
|
||||
expectAssignable<ForegroundColorName>('red');
|
||||
expectError<ForegroundColorName>('pink');
|
||||
|
||||
// -- Background types
|
||||
expectAssignable<BackgroundColorName>('bgRed');
|
||||
expectError<BackgroundColorName>('bgPink');
|
||||
|
||||
// -- Color types --
|
||||
expectAssignable<ColorName>('red');
|
||||
expectAssignable<ColorName>('bgRed');
|
||||
expectError<ColorName>('hotpink');
|
||||
expectError<ColorName>('bgHotpink');
|
||||
33
source/utilities.js
Normal file
33
source/utilities.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// TODO: When targeting Node.js 16, use `String.prototype.replaceAll`.
|
||||
export function stringReplaceAll(string, substring, replacer) {
|
||||
let index = string.indexOf(substring);
|
||||
if (index === -1) {
|
||||
return string;
|
||||
}
|
||||
|
||||
const substringLength = substring.length;
|
||||
let endIndex = 0;
|
||||
let returnValue = '';
|
||||
do {
|
||||
returnValue += string.slice(endIndex, index) + substring + replacer;
|
||||
endIndex = index + substringLength;
|
||||
index = string.indexOf(substring, endIndex);
|
||||
} while (index !== -1);
|
||||
|
||||
returnValue += string.slice(endIndex);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
||||
let endIndex = 0;
|
||||
let returnValue = '';
|
||||
do {
|
||||
const gotCR = string[index - 1] === '\r';
|
||||
returnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
||||
endIndex = index + 1;
|
||||
index = string.indexOf('\n', endIndex);
|
||||
} while (index !== -1);
|
||||
|
||||
returnValue += string.slice(endIndex);
|
||||
return returnValue;
|
||||
}
|
||||
236
source/vendor/ansi-styles/index.d.ts
vendored
Normal file
236
source/vendor/ansi-styles/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
export interface CSPair { // eslint-disable-line @typescript-eslint/naming-convention
|
||||
/**
|
||||
The ANSI terminal control sequence for starting this style.
|
||||
*/
|
||||
readonly open: string;
|
||||
|
||||
/**
|
||||
The ANSI terminal control sequence for ending this style.
|
||||
*/
|
||||
readonly close: string;
|
||||
}
|
||||
|
||||
export interface ColorBase {
|
||||
/**
|
||||
The ANSI terminal control sequence for ending this color.
|
||||
*/
|
||||
readonly close: string;
|
||||
|
||||
ansi(code: number): string;
|
||||
|
||||
ansi256(code: number): string;
|
||||
|
||||
ansi16m(red: number, green: number, blue: number): string;
|
||||
}
|
||||
|
||||
export interface Modifier {
|
||||
/**
|
||||
Resets the current color chain.
|
||||
*/
|
||||
readonly reset: CSPair;
|
||||
|
||||
/**
|
||||
Make text bold.
|
||||
*/
|
||||
readonly bold: CSPair;
|
||||
|
||||
/**
|
||||
Emitting only a small amount of light.
|
||||
*/
|
||||
readonly dim: CSPair;
|
||||
|
||||
/**
|
||||
Make text italic. (Not widely supported)
|
||||
*/
|
||||
readonly italic: CSPair;
|
||||
|
||||
/**
|
||||
Make text underline. (Not widely supported)
|
||||
*/
|
||||
readonly underline: CSPair;
|
||||
|
||||
/**
|
||||
Make text overline.
|
||||
|
||||
Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.
|
||||
*/
|
||||
readonly overline: CSPair;
|
||||
|
||||
/**
|
||||
Inverse background and foreground colors.
|
||||
*/
|
||||
readonly inverse: CSPair;
|
||||
|
||||
/**
|
||||
Prints the text, but makes it invisible.
|
||||
*/
|
||||
readonly hidden: CSPair;
|
||||
|
||||
/**
|
||||
Puts a horizontal line through the center of the text. (Not widely supported)
|
||||
*/
|
||||
readonly strikethrough: CSPair;
|
||||
}
|
||||
|
||||
export interface ForegroundColor {
|
||||
readonly black: CSPair;
|
||||
readonly red: CSPair;
|
||||
readonly green: CSPair;
|
||||
readonly yellow: CSPair;
|
||||
readonly blue: CSPair;
|
||||
readonly cyan: CSPair;
|
||||
readonly magenta: CSPair;
|
||||
readonly white: CSPair;
|
||||
|
||||
/**
|
||||
Alias for `blackBright`.
|
||||
*/
|
||||
readonly gray: CSPair;
|
||||
|
||||
/**
|
||||
Alias for `blackBright`.
|
||||
*/
|
||||
readonly grey: CSPair;
|
||||
|
||||
readonly blackBright: CSPair;
|
||||
readonly redBright: CSPair;
|
||||
readonly greenBright: CSPair;
|
||||
readonly yellowBright: CSPair;
|
||||
readonly blueBright: CSPair;
|
||||
readonly cyanBright: CSPair;
|
||||
readonly magentaBright: CSPair;
|
||||
readonly whiteBright: CSPair;
|
||||
}
|
||||
|
||||
export interface BackgroundColor {
|
||||
readonly bgBlack: CSPair;
|
||||
readonly bgRed: CSPair;
|
||||
readonly bgGreen: CSPair;
|
||||
readonly bgYellow: CSPair;
|
||||
readonly bgBlue: CSPair;
|
||||
readonly bgCyan: CSPair;
|
||||
readonly bgMagenta: CSPair;
|
||||
readonly bgWhite: CSPair;
|
||||
|
||||
/**
|
||||
Alias for `bgBlackBright`.
|
||||
*/
|
||||
readonly bgGray: CSPair;
|
||||
|
||||
/**
|
||||
Alias for `bgBlackBright`.
|
||||
*/
|
||||
readonly bgGrey: CSPair;
|
||||
|
||||
readonly bgBlackBright: CSPair;
|
||||
readonly bgRedBright: CSPair;
|
||||
readonly bgGreenBright: CSPair;
|
||||
readonly bgYellowBright: CSPair;
|
||||
readonly bgBlueBright: CSPair;
|
||||
readonly bgCyanBright: CSPair;
|
||||
readonly bgMagentaBright: CSPair;
|
||||
readonly bgWhiteBright: CSPair;
|
||||
}
|
||||
|
||||
export interface ConvertColor {
|
||||
/**
|
||||
Convert from the RGB color space to the ANSI 256 color space.
|
||||
|
||||
@param red - (`0...255`)
|
||||
@param green - (`0...255`)
|
||||
@param blue - (`0...255`)
|
||||
*/
|
||||
rgbToAnsi256(red: number, green: number, blue: number): number;
|
||||
|
||||
/**
|
||||
Convert from the RGB HEX color space to the RGB color space.
|
||||
|
||||
@param hex - A hexadecimal string containing RGB data.
|
||||
*/
|
||||
hexToRgb(hex: string): [red: number, green: number, blue: number];
|
||||
|
||||
/**
|
||||
Convert from the RGB HEX color space to the ANSI 256 color space.
|
||||
|
||||
@param hex - A hexadecimal string containing RGB data.
|
||||
*/
|
||||
hexToAnsi256(hex: string): number;
|
||||
|
||||
/**
|
||||
Convert from the ANSI 256 color space to the ANSI 16 color space.
|
||||
|
||||
@param code - A number representing the ANSI 256 color.
|
||||
*/
|
||||
ansi256ToAnsi(code: number): number;
|
||||
|
||||
/**
|
||||
Convert from the RGB color space to the ANSI 16 color space.
|
||||
|
||||
@param red - (`0...255`)
|
||||
@param green - (`0...255`)
|
||||
@param blue - (`0...255`)
|
||||
*/
|
||||
rgbToAnsi(red: number, green: number, blue: number): number;
|
||||
|
||||
/**
|
||||
Convert from the RGB HEX color space to the ANSI 16 color space.
|
||||
|
||||
@param hex - A hexadecimal string containing RGB data.
|
||||
*/
|
||||
hexToAnsi(hex: string): number;
|
||||
}
|
||||
|
||||
/**
|
||||
Basic modifier names.
|
||||
*/
|
||||
export type ModifierName = keyof Modifier;
|
||||
|
||||
/**
|
||||
Basic foreground color names.
|
||||
|
||||
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
||||
*/
|
||||
export type ForegroundColorName = keyof ForegroundColor;
|
||||
|
||||
/**
|
||||
Basic background color names.
|
||||
|
||||
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
||||
*/
|
||||
export type BackgroundColorName = keyof BackgroundColor;
|
||||
|
||||
/**
|
||||
Basic color names. The combination of foreground and background color names.
|
||||
|
||||
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
||||
*/
|
||||
export type ColorName = ForegroundColorName | BackgroundColorName;
|
||||
|
||||
/**
|
||||
Basic modifier names.
|
||||
*/
|
||||
export const modifierNames: readonly ModifierName[];
|
||||
|
||||
/**
|
||||
Basic foreground color names.
|
||||
*/
|
||||
export const foregroundColorNames: readonly ForegroundColorName[];
|
||||
|
||||
/**
|
||||
Basic background color names.
|
||||
*/
|
||||
export const backgroundColorNames: readonly BackgroundColorName[];
|
||||
|
||||
/*
|
||||
Basic color names. The combination of foreground and background color names.
|
||||
*/
|
||||
export const colorNames: readonly ColorName[];
|
||||
|
||||
declare const ansiStyles: {
|
||||
readonly modifier: Modifier;
|
||||
readonly color: ColorBase & ForegroundColor;
|
||||
readonly bgColor: ColorBase & BackgroundColor;
|
||||
readonly codes: ReadonlyMap<number, number>;
|
||||
} & ForegroundColor & BackgroundColor & Modifier & ConvertColor;
|
||||
|
||||
export default ansiStyles;
|
||||
223
source/vendor/ansi-styles/index.js
vendored
Normal file
223
source/vendor/ansi-styles/index.js
vendored
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
const ANSI_BACKGROUND_OFFSET = 10;
|
||||
|
||||
const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
|
||||
|
||||
const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
|
||||
|
||||
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
||||
|
||||
const styles = {
|
||||
modifier: {
|
||||
reset: [0, 0],
|
||||
// 21 isn't widely supported and 22 does the same thing
|
||||
bold: [1, 22],
|
||||
dim: [2, 22],
|
||||
italic: [3, 23],
|
||||
underline: [4, 24],
|
||||
overline: [53, 55],
|
||||
inverse: [7, 27],
|
||||
hidden: [8, 28],
|
||||
strikethrough: [9, 29],
|
||||
},
|
||||
color: {
|
||||
black: [30, 39],
|
||||
red: [31, 39],
|
||||
green: [32, 39],
|
||||
yellow: [33, 39],
|
||||
blue: [34, 39],
|
||||
magenta: [35, 39],
|
||||
cyan: [36, 39],
|
||||
white: [37, 39],
|
||||
|
||||
// Bright color
|
||||
blackBright: [90, 39],
|
||||
gray: [90, 39], // Alias of `blackBright`
|
||||
grey: [90, 39], // Alias of `blackBright`
|
||||
redBright: [91, 39],
|
||||
greenBright: [92, 39],
|
||||
yellowBright: [93, 39],
|
||||
blueBright: [94, 39],
|
||||
magentaBright: [95, 39],
|
||||
cyanBright: [96, 39],
|
||||
whiteBright: [97, 39],
|
||||
},
|
||||
bgColor: {
|
||||
bgBlack: [40, 49],
|
||||
bgRed: [41, 49],
|
||||
bgGreen: [42, 49],
|
||||
bgYellow: [43, 49],
|
||||
bgBlue: [44, 49],
|
||||
bgMagenta: [45, 49],
|
||||
bgCyan: [46, 49],
|
||||
bgWhite: [47, 49],
|
||||
|
||||
// Bright color
|
||||
bgBlackBright: [100, 49],
|
||||
bgGray: [100, 49], // Alias of `bgBlackBright`
|
||||
bgGrey: [100, 49], // Alias of `bgBlackBright`
|
||||
bgRedBright: [101, 49],
|
||||
bgGreenBright: [102, 49],
|
||||
bgYellowBright: [103, 49],
|
||||
bgBlueBright: [104, 49],
|
||||
bgMagentaBright: [105, 49],
|
||||
bgCyanBright: [106, 49],
|
||||
bgWhiteBright: [107, 49],
|
||||
},
|
||||
};
|
||||
|
||||
export const modifierNames = Object.keys(styles.modifier);
|
||||
export const foregroundColorNames = Object.keys(styles.color);
|
||||
export const backgroundColorNames = Object.keys(styles.bgColor);
|
||||
export const colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
||||
|
||||
function assembleStyles() {
|
||||
const codes = new Map();
|
||||
|
||||
for (const [groupName, group] of Object.entries(styles)) {
|
||||
for (const [styleName, style] of Object.entries(group)) {
|
||||
styles[styleName] = {
|
||||
open: `\u001B[${style[0]}m`,
|
||||
close: `\u001B[${style[1]}m`,
|
||||
};
|
||||
|
||||
group[styleName] = styles[styleName];
|
||||
|
||||
codes.set(style[0], style[1]);
|
||||
}
|
||||
|
||||
Object.defineProperty(styles, groupName, {
|
||||
value: group,
|
||||
enumerable: false,
|
||||
});
|
||||
}
|
||||
|
||||
Object.defineProperty(styles, 'codes', {
|
||||
value: codes,
|
||||
enumerable: false,
|
||||
});
|
||||
|
||||
styles.color.close = '\u001B[39m';
|
||||
styles.bgColor.close = '\u001B[49m';
|
||||
|
||||
styles.color.ansi = wrapAnsi16();
|
||||
styles.color.ansi256 = wrapAnsi256();
|
||||
styles.color.ansi16m = wrapAnsi16m();
|
||||
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
||||
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
||||
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
||||
|
||||
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
||||
Object.defineProperties(styles, {
|
||||
rgbToAnsi256: {
|
||||
value(red, green, blue) {
|
||||
// We use the extended greyscale palette here, with the exception of
|
||||
// black and white. normal palette only has 4 greyscale shades.
|
||||
if (red === green && green === blue) {
|
||||
if (red < 8) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
if (red > 248) {
|
||||
return 231;
|
||||
}
|
||||
|
||||
return Math.round(((red - 8) / 247) * 24) + 232;
|
||||
}
|
||||
|
||||
return 16
|
||||
+ (36 * Math.round(red / 255 * 5))
|
||||
+ (6 * Math.round(green / 255 * 5))
|
||||
+ Math.round(blue / 255 * 5);
|
||||
},
|
||||
enumerable: false,
|
||||
},
|
||||
hexToRgb: {
|
||||
value(hex) {
|
||||
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
||||
if (!matches) {
|
||||
return [0, 0, 0];
|
||||
}
|
||||
|
||||
let [colorString] = matches;
|
||||
|
||||
if (colorString.length === 3) {
|
||||
colorString = [...colorString].map(character => character + character).join('');
|
||||
}
|
||||
|
||||
const integer = Number.parseInt(colorString, 16);
|
||||
|
||||
return [
|
||||
/* eslint-disable no-bitwise */
|
||||
(integer >> 16) & 0xFF,
|
||||
(integer >> 8) & 0xFF,
|
||||
integer & 0xFF,
|
||||
/* eslint-enable no-bitwise */
|
||||
];
|
||||
},
|
||||
enumerable: false,
|
||||
},
|
||||
hexToAnsi256: {
|
||||
value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
||||
enumerable: false,
|
||||
},
|
||||
ansi256ToAnsi: {
|
||||
value(code) {
|
||||
if (code < 8) {
|
||||
return 30 + code;
|
||||
}
|
||||
|
||||
if (code < 16) {
|
||||
return 90 + (code - 8);
|
||||
}
|
||||
|
||||
let red;
|
||||
let green;
|
||||
let blue;
|
||||
|
||||
if (code >= 232) {
|
||||
red = (((code - 232) * 10) + 8) / 255;
|
||||
green = red;
|
||||
blue = red;
|
||||
} else {
|
||||
code -= 16;
|
||||
|
||||
const remainder = code % 36;
|
||||
|
||||
red = Math.floor(code / 36) / 5;
|
||||
green = Math.floor(remainder / 6) / 5;
|
||||
blue = (remainder % 6) / 5;
|
||||
}
|
||||
|
||||
const value = Math.max(red, green, blue) * 2;
|
||||
|
||||
if (value === 0) {
|
||||
return 30;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-bitwise
|
||||
let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
|
||||
|
||||
if (value === 2) {
|
||||
result += 60;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
enumerable: false,
|
||||
},
|
||||
rgbToAnsi: {
|
||||
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
||||
enumerable: false,
|
||||
},
|
||||
hexToAnsi: {
|
||||
value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
||||
enumerable: false,
|
||||
},
|
||||
});
|
||||
|
||||
return styles;
|
||||
}
|
||||
|
||||
const ansiStyles = assembleStyles();
|
||||
|
||||
export default ansiStyles;
|
||||
1
source/vendor/supports-color/browser.d.ts
vendored
Normal file
1
source/vendor/supports-color/browser.d.ts
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export {default} from './index.js';
|
||||
34
source/vendor/supports-color/browser.js
vendored
Normal file
34
source/vendor/supports-color/browser.js
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* eslint-env browser */
|
||||
|
||||
const level = (() => {
|
||||
if (!('navigator' in globalThis)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (globalThis.navigator.userAgentData) {
|
||||
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
|
||||
if (brand && brand.version > 93) {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
})();
|
||||
|
||||
const colorSupport = level !== 0 && {
|
||||
level,
|
||||
hasBasic: true,
|
||||
has256: level >= 2,
|
||||
has16m: level >= 3,
|
||||
};
|
||||
|
||||
const supportsColor = {
|
||||
stdout: colorSupport,
|
||||
stderr: colorSupport,
|
||||
};
|
||||
|
||||
export default supportsColor;
|
||||
55
source/vendor/supports-color/index.d.ts
vendored
Normal file
55
source/vendor/supports-color/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import type {WriteStream} from 'node:tty';
|
||||
|
||||
export type Options = {
|
||||
/**
|
||||
Whether `process.argv` should be sniffed for `--color` and `--no-color` flags.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly sniffFlags?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
Levels:
|
||||
- `0` - All colors disabled.
|
||||
- `1` - Basic 16 colors support.
|
||||
- `2` - ANSI 256 colors support.
|
||||
- `3` - Truecolor 16 million colors support.
|
||||
*/
|
||||
export type ColorSupportLevel = 0 | 1 | 2 | 3;
|
||||
|
||||
/**
|
||||
Detect whether the terminal supports color.
|
||||
*/
|
||||
export type ColorSupport = {
|
||||
/**
|
||||
The color level.
|
||||
*/
|
||||
level: ColorSupportLevel;
|
||||
|
||||
/**
|
||||
Whether basic 16 colors are supported.
|
||||
*/
|
||||
hasBasic: boolean;
|
||||
|
||||
/**
|
||||
Whether ANSI 256 colors are supported.
|
||||
*/
|
||||
has256: boolean;
|
||||
|
||||
/**
|
||||
Whether Truecolor 16 million colors are supported.
|
||||
*/
|
||||
has16m: boolean;
|
||||
};
|
||||
|
||||
export type ColorInfo = ColorSupport | false;
|
||||
|
||||
export function createSupportsColor(stream?: WriteStream, options?: Options): ColorInfo;
|
||||
|
||||
declare const supportsColor: {
|
||||
stdout: ColorInfo;
|
||||
stderr: ColorInfo;
|
||||
};
|
||||
|
||||
export default supportsColor;
|
||||
190
source/vendor/supports-color/index.js
vendored
Normal file
190
source/vendor/supports-color/index.js
vendored
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
import process from 'node:process';
|
||||
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 = globalThis.Deno?.args ?? 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('--');
|
||||
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
||||
}
|
||||
|
||||
const {env} = process;
|
||||
|
||||
let flagForceColor;
|
||||
if (
|
||||
hasFlag('no-color')
|
||||
|| hasFlag('no-colors')
|
||||
|| hasFlag('color=false')
|
||||
|| hasFlag('color=never')
|
||||
) {
|
||||
flagForceColor = 0;
|
||||
} else if (
|
||||
hasFlag('color')
|
||||
|| hasFlag('colors')
|
||||
|| hasFlag('color=true')
|
||||
|| hasFlag('color=always')
|
||||
) {
|
||||
flagForceColor = 1;
|
||||
}
|
||||
|
||||
function envForceColor() {
|
||||
if ('FORCE_COLOR' in env) {
|
||||
if (env.FORCE_COLOR === 'true') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (env.FORCE_COLOR === 'false') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
||||
}
|
||||
}
|
||||
|
||||
function translateLevel(level) {
|
||||
if (level === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
level,
|
||||
hasBasic: true,
|
||||
has256: level >= 2,
|
||||
has16m: level >= 3,
|
||||
};
|
||||
}
|
||||
|
||||
function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
||||
const noFlagForceColor = envForceColor();
|
||||
if (noFlagForceColor !== undefined) {
|
||||
flagForceColor = noFlagForceColor;
|
||||
}
|
||||
|
||||
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
||||
|
||||
if (forceColor === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sniffFlags) {
|
||||
if (hasFlag('color=16m')
|
||||
|| hasFlag('color=full')
|
||||
|| hasFlag('color=truecolor')) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (hasFlag('color=256')) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
const min = forceColor || 0;
|
||||
|
||||
if (env.TERM === 'dumb') {
|
||||
return min;
|
||||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
||||
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
||||
const osRelease = os.release().split('.');
|
||||
if (
|
||||
Number(osRelease[0]) >= 10
|
||||
&& Number(osRelease[2]) >= 10_586
|
||||
) {
|
||||
return Number(osRelease[2]) >= 14_931 ? 3 : 2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ('CI' in env) {
|
||||
if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return min;
|
||||
}
|
||||
|
||||
if ('TEAMCITY_VERSION' in env) {
|
||||
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
||||
}
|
||||
|
||||
if (env.COLORTERM === 'truecolor') {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (env.TERM === 'xterm-kitty') {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (env.TERM === 'xterm-ghostty') {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (env.TERM === 'wezterm') {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if ('TERM_PROGRAM' in env) {
|
||||
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
||||
|
||||
switch (env.TERM_PROGRAM) {
|
||||
case 'iTerm.app': {
|
||||
return version >= 3 ? 3 : 2;
|
||||
}
|
||||
|
||||
case 'Apple_Terminal': {
|
||||
return 2;
|
||||
}
|
||||
// No default
|
||||
}
|
||||
}
|
||||
|
||||
if (/-256(color)?$/i.test(env.TERM)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ('COLORTERM' in env) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return min;
|
||||
}
|
||||
|
||||
export function createSupportsColor(stream, options = {}) {
|
||||
const level = _supportsColor(stream, {
|
||||
streamIsTTY: stream && stream.isTTY,
|
||||
...options,
|
||||
});
|
||||
|
||||
return translateLevel(level);
|
||||
}
|
||||
|
||||
const supportsColor = {
|
||||
stdout: createSupportsColor({isTTY: tty.isatty(1)}),
|
||||
stderr: createSupportsColor({isTTY: tty.isatty(2)}),
|
||||
};
|
||||
|
||||
export default supportsColor;
|
||||
128
templates.js
128
templates.js
|
|
@ -1,128 +0,0 @@
|
|||
'use strict';
|
||||
const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
||||
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
||||
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
||||
const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
|
||||
|
||||
const ESCAPES = new Map([
|
||||
['n', '\n'],
|
||||
['r', '\r'],
|
||||
['t', '\t'],
|
||||
['b', '\b'],
|
||||
['f', '\f'],
|
||||
['v', '\v'],
|
||||
['0', '\0'],
|
||||
['\\', '\\'],
|
||||
['e', '\u001B'],
|
||||
['a', '\u0007']
|
||||
]);
|
||||
|
||||
function unescape(c) {
|
||||
if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
|
||||
return String.fromCharCode(parseInt(c.slice(1), 16));
|
||||
}
|
||||
|
||||
return ESCAPES.get(c) || c;
|
||||
}
|
||||
|
||||
function parseArguments(name, args) {
|
||||
const results = [];
|
||||
const chunks = args.trim().split(/\s*,\s*/g);
|
||||
let matches;
|
||||
|
||||
for (const chunk of chunks) {
|
||||
if (!isNaN(chunk)) {
|
||||
results.push(Number(chunk));
|
||||
} else if ((matches = chunk.match(STRING_REGEX))) {
|
||||
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
|
||||
} else {
|
||||
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
function parseStyle(style) {
|
||||
STYLE_REGEX.lastIndex = 0;
|
||||
|
||||
const results = [];
|
||||
let matches;
|
||||
|
||||
while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
||||
const name = matches[1];
|
||||
|
||||
if (matches[2]) {
|
||||
const args = parseArguments(name, matches[2]);
|
||||
results.push([name].concat(args));
|
||||
} else {
|
||||
results.push([name]);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
function buildStyle(chalk, styles) {
|
||||
const enabled = {};
|
||||
|
||||
for (const layer of styles) {
|
||||
for (const style of layer.styles) {
|
||||
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
||||
}
|
||||
}
|
||||
|
||||
let current = chalk;
|
||||
for (const styleName of Object.keys(enabled)) {
|
||||
if (Array.isArray(enabled[styleName])) {
|
||||
if (!(styleName in current)) {
|
||||
throw new Error(`Unknown Chalk style: ${styleName}`);
|
||||
}
|
||||
|
||||
if (enabled[styleName].length > 0) {
|
||||
current = current[styleName].apply(current, enabled[styleName]);
|
||||
} else {
|
||||
current = current[styleName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
module.exports = (chalk, tmp) => {
|
||||
const styles = [];
|
||||
const chunks = [];
|
||||
let chunk = [];
|
||||
|
||||
// eslint-disable-next-line max-params
|
||||
tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
|
||||
if (escapeChar) {
|
||||
chunk.push(unescape(escapeChar));
|
||||
} else if (style) {
|
||||
const str = chunk.join('');
|
||||
chunk = [];
|
||||
chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
|
||||
styles.push({inverse, styles: parseStyle(style)});
|
||||
} else if (close) {
|
||||
if (styles.length === 0) {
|
||||
throw new Error('Found extraneous } in Chalk template literal');
|
||||
}
|
||||
|
||||
chunks.push(buildStyle(chalk, styles)(chunk.join('')));
|
||||
chunk = [];
|
||||
styles.pop();
|
||||
} else {
|
||||
chunk.push(chr);
|
||||
}
|
||||
});
|
||||
|
||||
chunks.push(chunk.join(''));
|
||||
|
||||
if (styles.length > 0) {
|
||||
const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
|
||||
return chunks.join('');
|
||||
};
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
'use strict';
|
||||
const chalk = require('..');
|
||||
import chalk, {chalkStderr} from '../source/index.js';
|
||||
|
||||
console.log(chalk.hex('#ff6159')('test'));
|
||||
console.log(`${chalk.hex('#ff6159')('testout')} ${chalkStderr.hex('#ff6159')('testerr')}`);
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
'use strict';
|
||||
const resolveFrom = require('resolve-from');
|
||||
|
||||
module.exports = dir => {
|
||||
require.cache[resolveFrom(dir, 'supports-color')] = {
|
||||
exports: {
|
||||
level: 3,
|
||||
hasBasic: true,
|
||||
has256: true,
|
||||
has16m: true
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
@ -1,53 +1,60 @@
|
|||
import process from 'node:process';
|
||||
import test from 'ava';
|
||||
import chalk, {Chalk, chalkStderr} from '../source/index.js';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const m = require('..');
|
||||
chalk.level = 3;
|
||||
chalkStderr.level = 3;
|
||||
|
||||
console.log('TERM:', process.env.TERM || '[none]');
|
||||
console.log('platform:', process.platform || '[unknown]');
|
||||
|
||||
test('don\'t add any styling when called as the base function', t => {
|
||||
t.is(m('foo'), 'foo');
|
||||
t.is(chalk('foo'), 'foo');
|
||||
});
|
||||
|
||||
test('support multiple arguments in base function', t => {
|
||||
t.is(m('hello', 'there'), 'hello there');
|
||||
t.is(chalk('hello', 'there'), 'hello there');
|
||||
});
|
||||
|
||||
test('support automatic casting to string', t => {
|
||||
t.is(chalk(['hello', 'there']), 'hello,there');
|
||||
t.is(chalk(123), '123');
|
||||
|
||||
t.is(chalk.bold(['foo', 'bar']), '\u001B[1mfoo,bar\u001B[22m');
|
||||
t.is(chalk.green(98_765), '\u001B[32m98765\u001B[39m');
|
||||
});
|
||||
|
||||
test('style string', t => {
|
||||
t.is(m.underline('foo'), '\u001B[4mfoo\u001B[24m');
|
||||
t.is(m.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(m.bgRed('foo'), '\u001B[41mfoo\u001B[49m');
|
||||
t.is(chalk.underline('foo'), '\u001B[4mfoo\u001B[24m');
|
||||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(chalk.bgRed('foo'), '\u001B[41mfoo\u001B[49m');
|
||||
});
|
||||
|
||||
test('support applying multiple styles at once', t => {
|
||||
t.is(m.red.bgGreen.underline('foo'), '\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39m');
|
||||
t.is(m.underline.red.bgGreen('foo'), '\u001B[4m\u001B[31m\u001B[42mfoo\u001B[49m\u001B[39m\u001B[24m');
|
||||
t.is(chalk.red.bgGreen.underline('foo'), '\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39m');
|
||||
t.is(chalk.underline.red.bgGreen('foo'), '\u001B[4m\u001B[31m\u001B[42mfoo\u001B[49m\u001B[39m\u001B[24m');
|
||||
});
|
||||
|
||||
test('support nesting styles', t => {
|
||||
t.is(
|
||||
m.red('foo' + m.underline.bgBlue('bar') + '!'),
|
||||
'\u001B[31mfoo\u001B[4m\u001B[44mbar\u001B[49m\u001B[24m!\u001B[39m'
|
||||
chalk.red('foo' + chalk.underline.bgBlue('bar') + '!'),
|
||||
'\u001B[31mfoo\u001B[4m\u001B[44mbar\u001B[49m\u001B[24m!\u001B[39m',
|
||||
);
|
||||
});
|
||||
|
||||
test('support nesting styles of the same type (color, underline, bg)', t => {
|
||||
t.is(
|
||||
m.red('a' + m.yellow('b' + m.green('c') + 'b') + 'c'),
|
||||
'\u001B[31ma\u001B[33mb\u001B[32mc\u001B[33mb\u001B[31mc\u001B[39m'
|
||||
chalk.red('a' + chalk.yellow('b' + chalk.green('c') + 'b') + 'c'),
|
||||
'\u001B[31ma\u001B[33mb\u001B[32mc\u001B[39m\u001B[31m\u001B[33mb\u001B[39m\u001B[31mc\u001B[39m',
|
||||
);
|
||||
});
|
||||
|
||||
test('reset all styles with `.reset()`', t => {
|
||||
t.is(m.reset(m.red.bgGreen.underline('foo') + 'foo'), '\u001B[0m\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39mfoo\u001B[0m');
|
||||
t.is(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\u001B[0m\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39mfoo\u001B[0m');
|
||||
});
|
||||
|
||||
test('support caching multiple styles', t => {
|
||||
const red = m.red;
|
||||
const green = m.green;
|
||||
const {red, green} = chalk.red;
|
||||
const redBold = red.bold;
|
||||
const greenBold = green.bold;
|
||||
|
||||
|
|
@ -57,44 +64,63 @@ test('support caching multiple styles', t => {
|
|||
});
|
||||
|
||||
test('alias gray to grey', t => {
|
||||
t.is(m.grey('foo'), '\u001B[90mfoo\u001B[39m');
|
||||
t.is(chalk.grey('foo'), '\u001B[90mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('support variable number of arguments', t => {
|
||||
t.is(m.red('foo', 'bar'), '\u001B[31mfoo bar\u001B[39m');
|
||||
t.is(chalk.red('foo', 'bar'), '\u001B[31mfoo bar\u001B[39m');
|
||||
});
|
||||
|
||||
test('support falsy values', t => {
|
||||
t.is(m.red(0), '\u001B[31m0\u001B[39m');
|
||||
t.is(chalk.red(0), '\u001B[31m0\u001B[39m');
|
||||
});
|
||||
|
||||
test('don\'t output escape codes if the input is empty', t => {
|
||||
t.is(m.red(), '');
|
||||
t.is(m.red.blue.black(), '');
|
||||
t.is(chalk.red(), '');
|
||||
t.is(chalk.red.blue.black(), '');
|
||||
});
|
||||
|
||||
test('keep Function.prototype methods', t => {
|
||||
t.is(m.grey.apply(null, ['foo']), '\u001B[90mfoo\u001B[39m');
|
||||
t.is(m.reset(m.red.bgGreen.underline.bind(null)('foo') + 'foo'), '\u001B[0m\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39mfoo\u001B[0m');
|
||||
t.is(m.red.blue.black.call(null), '');
|
||||
t.is(Reflect.apply(chalk.grey, null, ['foo']), '\u001B[90mfoo\u001B[39m');
|
||||
t.is(chalk.reset(chalk.red.bgGreen.underline.bind(null)('foo') + 'foo'), '\u001B[0m\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39mfoo\u001B[0m');
|
||||
t.is(chalk.red.blue.black.call(null), '');
|
||||
});
|
||||
|
||||
test('line breaks should open and close colors', t => {
|
||||
t.is(m.grey('hello\nworld'), '\u001B[90mhello\u001B[39m\n\u001B[90mworld\u001B[39m');
|
||||
t.is(chalk.grey('hello\nworld'), '\u001B[90mhello\u001B[39m\n\u001B[90mworld\u001B[39m');
|
||||
});
|
||||
|
||||
test('line breaks should open and close colors with CRLF', t => {
|
||||
t.is(chalk.grey('hello\r\nworld'), '\u001B[90mhello\u001B[39m\r\n\u001B[90mworld\u001B[39m');
|
||||
});
|
||||
|
||||
test('properly convert RGB to 16 colors on basic color terminals', t => {
|
||||
t.is(new m.constructor({level: 1}).hex('#FF0000')('hello'), '\u001B[91mhello\u001B[39m');
|
||||
t.is(new m.constructor({level: 1}).bgHex('#FF0000')('hello'), '\u001B[101mhello\u001B[49m');
|
||||
t.is(new Chalk({level: 1}).hex('#FF0000')('hello'), '\u001B[91mhello\u001B[39m');
|
||||
t.is(new Chalk({level: 1}).bgHex('#FF0000')('hello'), '\u001B[101mhello\u001B[49m');
|
||||
});
|
||||
|
||||
test('properly convert RGB to 256 colors on basic color terminals', t => {
|
||||
t.is(new m.constructor({level: 2}).hex('#FF0000')('hello'), '\u001B[38;5;196mhello\u001B[39m');
|
||||
t.is(new m.constructor({level: 2}).bgHex('#FF0000')('hello'), '\u001B[48;5;196mhello\u001B[49m');
|
||||
t.is(new m.constructor({level: 3}).bgHex('#FF0000')('hello'), '\u001B[48;2;255;0;0mhello\u001B[49m');
|
||||
t.is(new Chalk({level: 2}).hex('#FF0000')('hello'), '\u001B[38;5;196mhello\u001B[39m');
|
||||
t.is(new Chalk({level: 2}).bgHex('#FF0000')('hello'), '\u001B[48;5;196mhello\u001B[49m');
|
||||
t.is(new Chalk({level: 3}).bgHex('#FF0000')('hello'), '\u001B[48;2;255;0;0mhello\u001B[49m');
|
||||
});
|
||||
|
||||
test('don\'t emit RGB codes if level is 0', t => {
|
||||
t.is(new m.constructor({level: 0}).hex('#FF0000')('hello'), 'hello');
|
||||
t.is(new m.constructor({level: 0}).bgHex('#FF0000')('hello'), 'hello');
|
||||
t.is(new Chalk({level: 0}).hex('#FF0000')('hello'), 'hello');
|
||||
t.is(new Chalk({level: 0}).bgHex('#FF0000')('hello'), 'hello');
|
||||
});
|
||||
|
||||
test('supports blackBright color', t => {
|
||||
t.is(chalk.blackBright('foo'), '\u001B[90mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('sets correct level for chalkStderr and respects it', t => {
|
||||
t.is(chalkStderr.level, 3);
|
||||
t.is(chalkStderr.red.bold('foo'), '\u001B[31m\u001B[1mfoo\u001B[22m\u001B[39m');
|
||||
});
|
||||
|
||||
test('keeps function prototype methods', t => {
|
||||
t.is(chalk.apply(chalk, ['foo']), 'foo');
|
||||
t.is(chalk.bind(chalk, 'foo')(), 'foo');
|
||||
t.is(chalk.call(chalk, 'foo'), 'foo');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
import test from 'ava';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const m = require('..');
|
||||
|
||||
test('create an isolated context where colors can be disabled (by level)', t => {
|
||||
const ctx = new m.constructor({level: 0, enabled: true});
|
||||
t.is(ctx.red('foo'), 'foo');
|
||||
t.is(m.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
ctx.level = 2;
|
||||
t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('create an isolated context where colors can be disabled (by enabled flag)', t => {
|
||||
const ctx = new m.constructor({enabled: false});
|
||||
t.is(ctx.red('foo'), 'foo');
|
||||
t.is(m.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
ctx.enabled = true;
|
||||
t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
});
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
import test from 'ava';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const m = require('..');
|
||||
|
||||
test('don\'t output colors when manually disabled', t => {
|
||||
m.enabled = false;
|
||||
t.is(m.red('foo'), 'foo');
|
||||
m.enabled = true;
|
||||
});
|
||||
|
||||
test('enable/disable colors based on overall chalk enabled property, not individual instances', t => {
|
||||
m.enabled = false;
|
||||
const red = m.red;
|
||||
t.false(red.enabled);
|
||||
m.enabled = true;
|
||||
t.true(red.enabled);
|
||||
m.enabled = true;
|
||||
});
|
||||
|
||||
test('propagate enable/disable changes from child colors', t => {
|
||||
m.enabled = false;
|
||||
const red = m.red;
|
||||
t.false(red.enabled);
|
||||
t.false(m.enabled);
|
||||
red.enabled = true;
|
||||
t.true(red.enabled);
|
||||
t.true(m.enabled);
|
||||
m.enabled = false;
|
||||
t.false(red.enabled);
|
||||
t.false(m.enabled);
|
||||
m.enabled = true;
|
||||
});
|
||||
24
test/instance.js
Normal file
24
test/instance.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import test from 'ava';
|
||||
import chalk, {Chalk} from '../source/index.js';
|
||||
|
||||
chalk.level = 1;
|
||||
|
||||
test('create an isolated context where colors can be disabled (by level)', t => {
|
||||
const instance = new Chalk({level: 0});
|
||||
t.is(instance.red('foo'), 'foo');
|
||||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
instance.level = 2;
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('the `level` option should be a number from 0 to 3', t => {
|
||||
/* eslint-disable no-new */
|
||||
t.throws(() => {
|
||||
new Chalk({level: 10});
|
||||
}, {message: /should be an integer from 0 to 3/});
|
||||
|
||||
t.throws(() => {
|
||||
new Chalk({level: -1});
|
||||
}, {message: /should be an integer from 0 to 3/});
|
||||
/* eslint-enable no-new */
|
||||
});
|
||||
|
|
@ -1,44 +1,43 @@
|
|||
import path from 'path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import test from 'ava';
|
||||
import execa from 'execa';
|
||||
import {execaNode} from 'execa';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const m = require('..');
|
||||
chalk.level = 1;
|
||||
|
||||
test('don\'t output colors when manually disabled', t => {
|
||||
const oldLevel = m.level;
|
||||
m.level = 0;
|
||||
t.is(m.red('foo'), 'foo');
|
||||
m.level = oldLevel;
|
||||
const oldLevel = chalk.level;
|
||||
chalk.level = 0;
|
||||
t.is(chalk.red('foo'), 'foo');
|
||||
chalk.level = oldLevel;
|
||||
});
|
||||
|
||||
test('enable/disable colors based on overall chalk enabled property, not individual instances', t => {
|
||||
const oldLevel = m.level;
|
||||
m.level = 1;
|
||||
const red = m.red;
|
||||
test('enable/disable colors based on overall chalk .level property, not individual instances', t => {
|
||||
const oldLevel = chalk.level;
|
||||
chalk.level = 1;
|
||||
const {red} = chalk;
|
||||
t.is(red.level, 1);
|
||||
m.level = 0;
|
||||
t.is(red.level, m.level);
|
||||
m.level = oldLevel;
|
||||
chalk.level = 0;
|
||||
t.is(red.level, chalk.level);
|
||||
chalk.level = oldLevel;
|
||||
});
|
||||
|
||||
test('propagate enable/disable changes from child colors', t => {
|
||||
const oldLevel = m.level;
|
||||
m.level = 1;
|
||||
const red = m.red;
|
||||
const oldLevel = chalk.level;
|
||||
chalk.level = 1;
|
||||
const {red} = chalk;
|
||||
t.is(red.level, 1);
|
||||
t.is(m.level, 1);
|
||||
t.is(chalk.level, 1);
|
||||
red.level = 0;
|
||||
t.is(red.level, 0);
|
||||
t.is(m.level, 0);
|
||||
m.level = 1;
|
||||
t.is(chalk.level, 0);
|
||||
chalk.level = 1;
|
||||
t.is(red.level, 1);
|
||||
t.is(m.level, 1);
|
||||
m.level = oldLevel;
|
||||
t.is(chalk.level, 1);
|
||||
chalk.level = oldLevel;
|
||||
});
|
||||
|
||||
test('disable colors if they are not supported', async t => {
|
||||
t.is(await execa.stdout('node', [path.join(__dirname, '_fixture')]), 'test');
|
||||
const {stdout} = await execaNode(fileURLToPath(new URL('_fixture.js', import.meta.url)));
|
||||
t.is(stdout, 'testout testerr');
|
||||
});
|
||||
|
|
|
|||
24
test/no-color-support.js
Normal file
24
test/no-color-support.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import test from 'ava';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
// TODO: Do this when ESM supports loader hooks
|
||||
// Spoof supports-color
|
||||
// require('./_supports-color')(__dirname, {
|
||||
// stdout: {
|
||||
// level: 0,
|
||||
// hasBasic: false,
|
||||
// has256: false,
|
||||
// has16m: false
|
||||
// },
|
||||
// stderr: {
|
||||
// level: 0,
|
||||
// hasBasic: false,
|
||||
// has256: false,
|
||||
// has16m: false
|
||||
// }
|
||||
// });
|
||||
|
||||
test('colors can be forced by using chalk.level', t => {
|
||||
chalk.level = 1;
|
||||
t.is(chalk.green('hello'), '\u001B[32mhello\u001B[39m');
|
||||
});
|
||||
|
|
@ -1,169 +0,0 @@
|
|||
import test from 'ava';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const m = require('..');
|
||||
|
||||
test('return an empty string for an empty literal', t => {
|
||||
const ctx = m.constructor();
|
||||
t.is(ctx``, '');
|
||||
});
|
||||
|
||||
test('return a regular string for a literal with no templates', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
t.is(ctx`hello`, 'hello');
|
||||
});
|
||||
|
||||
test('correctly perform template parsing', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
t.is(ctx`{bold Hello, {cyan World!} This is a} test. {green Woo!}`,
|
||||
ctx.bold('Hello,', ctx.cyan('World!'), 'This is a') + ' test. ' + ctx.green('Woo!'));
|
||||
});
|
||||
|
||||
test('correctly perform template substitutions', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
const name = 'Sindre';
|
||||
const exclamation = 'Neat';
|
||||
t.is(ctx`{bold Hello, {cyan.inverse ${name}!} This is a} test. {green ${exclamation}!}`,
|
||||
ctx.bold('Hello,', ctx.cyan.inverse(name + '!'), 'This is a') + ' test. ' + ctx.green(exclamation + '!'));
|
||||
});
|
||||
|
||||
test('correctly parse and evaluate color-convert functions', t => {
|
||||
const ctx = m.constructor({level: 3});
|
||||
t.is(ctx`{bold.rgb(144,10,178).inverse Hello, {~inverse there!}}`,
|
||||
'\u001B[1m\u001B[38;2;144;10;178m\u001B[7mHello, ' +
|
||||
'\u001B[27m\u001B[39m\u001B[22m\u001B[1m' +
|
||||
'\u001B[38;2;144;10;178mthere!\u001B[39m\u001B[22m');
|
||||
|
||||
t.is(ctx`{bold.bgRgb(144,10,178).inverse Hello, {~inverse there!}}`,
|
||||
'\u001B[1m\u001B[48;2;144;10;178m\u001B[7mHello, ' +
|
||||
'\u001B[27m\u001B[49m\u001B[22m\u001B[1m' +
|
||||
'\u001B[48;2;144;10;178mthere!\u001B[49m\u001B[22m');
|
||||
});
|
||||
|
||||
test('properly handle escapes', t => {
|
||||
const ctx = m.constructor({level: 3});
|
||||
t.is(ctx`{bold hello \{in brackets\}}`,
|
||||
'\u001B[1mhello {in brackets}\u001B[22m');
|
||||
});
|
||||
|
||||
test('throw if there is an unclosed block', t => {
|
||||
const ctx = m.constructor({level: 3});
|
||||
try {
|
||||
console.log(ctx`{bold this shouldn't appear ever\}`);
|
||||
t.fail();
|
||||
} catch (err) {
|
||||
t.is(err.message, 'Chalk template literal is missing 1 closing bracket (`}`)');
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(ctx`{bold this shouldn't {inverse appear {underline ever\} :) \}`);
|
||||
t.fail();
|
||||
} catch (err) {
|
||||
t.is(err.message, 'Chalk template literal is missing 3 closing brackets (`}`)');
|
||||
}
|
||||
});
|
||||
|
||||
test('throw if there is an invalid style', t => {
|
||||
const ctx = m.constructor({level: 3});
|
||||
try {
|
||||
console.log(ctx`{abadstylethatdoesntexist this shouldn't appear ever}`);
|
||||
t.fail();
|
||||
} catch (err) {
|
||||
t.is(err.message, 'Unknown Chalk style: abadstylethatdoesntexist');
|
||||
}
|
||||
});
|
||||
|
||||
test('properly style multiline color blocks', t => {
|
||||
const ctx = m.constructor({level: 3});
|
||||
t.is(
|
||||
ctx`{bold
|
||||
Hello! This is a
|
||||
${'multiline'} block!
|
||||
:)
|
||||
} {underline
|
||||
I hope you enjoy
|
||||
}`,
|
||||
'\u001B[1m\u001B[22m\n' +
|
||||
'\u001B[1m\t\t\tHello! This is a\u001B[22m\n' +
|
||||
'\u001B[1m\t\t\tmultiline block!\u001B[22m\n' +
|
||||
'\u001B[1m\t\t\t:)\u001B[22m\n' +
|
||||
'\u001B[1m\t\t\u001B[22m \u001B[4m\u001B[24m\n' +
|
||||
'\u001B[4m\t\t\tI hope you enjoy\u001B[24m\n' +
|
||||
'\u001B[4m\t\t\u001B[24m'
|
||||
);
|
||||
});
|
||||
|
||||
test('escape interpolated values', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
t.is(ctx`Hello {bold hi}`, 'Hello hi');
|
||||
t.is(ctx`Hello ${'{bold hi}'}`, 'Hello {bold hi}');
|
||||
});
|
||||
|
||||
test('allow custom colors (themes) on custom contexts', t => {
|
||||
const ctx = m.constructor({level: 3});
|
||||
ctx.rose = ctx.hex('#F6D9D9');
|
||||
t.is(ctx`Hello, {rose Rose}.`, 'Hello, \u001B[38;2;246;217;217mRose\u001B[39m.');
|
||||
});
|
||||
|
||||
test('correctly parse newline literals (bug #184)', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
t.is(ctx`Hello
|
||||
{red there}`, 'Hello\nthere');
|
||||
});
|
||||
|
||||
test('correctly parse newline escapes (bug #177)', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
t.is(ctx`Hello\nthere!`, `Hello\nthere!`);
|
||||
});
|
||||
|
||||
test('correctly parse escape in parameters (bug #177 comment 318622809)', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
const str = '\\';
|
||||
t.is(ctx`{blue ${str}}`, '\\');
|
||||
});
|
||||
|
||||
test('correctly parses unicode/hex escapes', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
t.is(ctx`\u0078ylophones are fo\x78y! {magenta.inverse \u0078ylophones are fo\x78y!}`,
|
||||
'xylophones are foxy! xylophones are foxy!');
|
||||
});
|
||||
|
||||
test('correctly parses string arguments', t => {
|
||||
const ctx = m.constructor({level: 3});
|
||||
t.is(ctx`{keyword('black').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
|
||||
t.is(ctx`{keyword('blac\x6B').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
|
||||
t.is(ctx`{keyword('blac\u006B').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
|
||||
});
|
||||
|
||||
test('throws if a bad argument is encountered', t => {
|
||||
const ctx = m.constructor({level: 3}); // Keep level at least 1 in case we optimize for disabled chalk instances
|
||||
try {
|
||||
console.log(ctx`{keyword(????) hi}`);
|
||||
t.fail();
|
||||
} catch (err) {
|
||||
t.is(err.message, 'Invalid Chalk template style argument: ???? (in style \'keyword\')');
|
||||
}
|
||||
});
|
||||
|
||||
test('throws if an extra unescaped } is found', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
try {
|
||||
console.log(ctx`{red hi!}}`);
|
||||
t.fail();
|
||||
} catch (err) {
|
||||
t.is(err.message, 'Found extraneous } in Chalk template literal');
|
||||
}
|
||||
});
|
||||
|
||||
test('should not parse upper-case escapes', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
t.is(ctx`\N\n\T\t\X07\x07\U000A\u000A\U000a\u000a`, 'N\nT\tX07\x07U000A\u000AU000a\u000A');
|
||||
});
|
||||
|
||||
test('should properly handle undefined template interpolated values', t => {
|
||||
const ctx = m.constructor({level: 0});
|
||||
t.is(ctx`hello ${undefined}`, 'hello undefined');
|
||||
t.is(ctx`hello ${null}`, 'hello null');
|
||||
});
|
||||
|
|
@ -1,47 +1,39 @@
|
|||
import test from 'ava';
|
||||
import chalk, {Chalk} from '../source/index.js';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
chalk.level = 1;
|
||||
|
||||
const m = require('..');
|
||||
|
||||
test('visible: normal output when enabled', t => {
|
||||
const ctx = new m.constructor({level: 3, enabled: true});
|
||||
t.is(ctx.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(ctx.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('visible: no output when disabled', t => {
|
||||
const ctx = new m.constructor({level: 3, enabled: false});
|
||||
t.is(ctx.red.visible('foo'), '');
|
||||
t.is(ctx.visible.red('foo'), '');
|
||||
test('visible: normal output when level > 0', t => {
|
||||
const instance = new Chalk({level: 3});
|
||||
t.is(instance.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('visible: no output when level is too low', t => {
|
||||
const ctx = new m.constructor({level: 0, enabled: true});
|
||||
t.is(ctx.visible.red('foo'), '');
|
||||
t.is(ctx.red.visible('foo'), '');
|
||||
const instance = new Chalk({level: 0});
|
||||
t.is(instance.visible.red('foo'), '');
|
||||
t.is(instance.red.visible('foo'), '');
|
||||
});
|
||||
|
||||
test('test switching back and forth between enabled and disabled', t => {
|
||||
const ctx = new m.constructor({level: 3, enabled: true});
|
||||
t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(ctx.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(ctx.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(ctx.visible('foo'), 'foo');
|
||||
t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
test('test switching back and forth between level == 0 and level > 0', t => {
|
||||
const instance = new Chalk({level: 3});
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.visible('foo'), 'foo');
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
|
||||
ctx.enabled = false;
|
||||
t.is(ctx.red('foo'), 'foo');
|
||||
t.is(ctx.visible('foo'), '');
|
||||
t.is(ctx.visible.red('foo'), '');
|
||||
t.is(ctx.red.visible('foo'), '');
|
||||
t.is(ctx.red('foo'), 'foo');
|
||||
instance.level = 0;
|
||||
t.is(instance.red('foo'), 'foo');
|
||||
t.is(instance.visible('foo'), '');
|
||||
t.is(instance.visible.red('foo'), '');
|
||||
t.is(instance.red.visible('foo'), '');
|
||||
t.is(instance.red('foo'), 'foo');
|
||||
|
||||
ctx.enabled = true;
|
||||
t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(ctx.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(ctx.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(ctx.visible('foo'), 'foo');
|
||||
t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
instance.level = 3;
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
t.is(instance.visible('foo'), 'foo');
|
||||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
import test from 'ava';
|
||||
import importFresh from 'import-fresh';
|
||||
import resolveFrom from 'resolve-from';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
let originalEnv;
|
||||
let originalPlatform;
|
||||
|
||||
test.before(() => {
|
||||
originalEnv = process.env;
|
||||
originalPlatform = process.platform;
|
||||
});
|
||||
|
||||
test.after(() => {
|
||||
process.env = originalEnv;
|
||||
Object.defineProperty(process, 'platform', {value: originalPlatform});
|
||||
});
|
||||
|
||||
test.beforeEach(() => {
|
||||
process.env = {};
|
||||
Object.defineProperty(process, 'platform', {value: 'win32'});
|
||||
// Since chalk internally modifies `ansiStyles.blue.open`, `ansi-styles` needs
|
||||
// to be removed from the require cache for `require-uncached` to work
|
||||
delete require.cache[resolveFrom(__dirname, 'ansi-styles')];
|
||||
});
|
||||
|
||||
test('detect a simple term if TERM isn\'t set', t => {
|
||||
delete process.env.TERM;
|
||||
const m = importFresh('..');
|
||||
t.is(m.blue('foo'), '\u001B[94mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('replace blue foreground color in cmd.exe', t => {
|
||||
process.env.TERM = 'dumb';
|
||||
const m = importFresh('..');
|
||||
t.is(m.blue('foo'), '\u001B[94mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('don\'t replace blue foreground color in xterm based terminals', t => {
|
||||
process.env.TERM = 'xterm-256color';
|
||||
const m = importFresh('..');
|
||||
t.is(m.blue('foo'), '\u001B[34mfoo\u001B[39m');
|
||||
});
|
||||
|
||||
test('don\'t apply dimmed styling on gray strings, see https://github.com/chalk/chalk/issues/58', t => {
|
||||
process.env.TERM = 'dumb';
|
||||
const m = importFresh('..');
|
||||
t.is(m.gray.dim('foo'), '\u001B[90mfoo\u001B[22m\u001B[39m');
|
||||
});
|
||||
|
||||
test('apply dimmed styling on xterm compatible terminals', t => {
|
||||
process.env.TERM = 'xterm';
|
||||
const m = importFresh('..');
|
||||
t.is(m.gray.dim('foo'), '\u001B[90m\u001B[2mfoo\u001B[22m\u001B[39m');
|
||||
});
|
||||
|
||||
test('apply dimmed styling on strings of other colors', t => {
|
||||
process.env.TERM = 'dumb';
|
||||
const m = importFresh('..');
|
||||
t.is(m.blue.dim('foo'), '\u001B[94m\u001B[2mfoo\u001B[22m\u001B[39m');
|
||||
});
|
||||
97
types/index.d.ts
vendored
97
types/index.d.ts
vendored
|
|
@ -1,97 +0,0 @@
|
|||
// Type definitions for Chalk
|
||||
// Definitions by: Thomas Sauer <https://github.com/t-sauer>
|
||||
|
||||
export const enum Level {
|
||||
None = 0,
|
||||
Basic = 1,
|
||||
Ansi256 = 2,
|
||||
TrueColor = 3
|
||||
}
|
||||
|
||||
export interface ChalkOptions {
|
||||
enabled?: boolean;
|
||||
level?: Level;
|
||||
}
|
||||
|
||||
export interface ChalkConstructor {
|
||||
new (options?: ChalkOptions): Chalk;
|
||||
(options?: ChalkOptions): Chalk;
|
||||
}
|
||||
|
||||
export interface ColorSupport {
|
||||
level: Level;
|
||||
hasBasic: boolean;
|
||||
has256: boolean;
|
||||
has16m: boolean;
|
||||
}
|
||||
|
||||
export interface Chalk {
|
||||
(...text: string[]): string;
|
||||
(text: TemplateStringsArray, ...placeholders: string[]): string;
|
||||
constructor: ChalkConstructor;
|
||||
enabled: boolean;
|
||||
level: Level;
|
||||
rgb(r: number, g: number, b: number): this;
|
||||
hsl(h: number, s: number, l: number): this;
|
||||
hsv(h: number, s: number, v: number): this;
|
||||
hwb(h: number, w: number, b: number): this;
|
||||
bgHex(color: string): this;
|
||||
bgKeyword(color: string): this;
|
||||
bgRgb(r: number, g: number, b: number): this;
|
||||
bgHsl(h: number, s: number, l: number): this;
|
||||
bgHsv(h: number, s: number, v: number): this;
|
||||
bgHwb(h: number, w: number, b: number): this;
|
||||
hex(color: string): this;
|
||||
keyword(color: string): this;
|
||||
|
||||
readonly reset: this;
|
||||
readonly bold: this;
|
||||
readonly dim: this;
|
||||
readonly italic: this;
|
||||
readonly underline: this;
|
||||
readonly inverse: this;
|
||||
readonly hidden: this;
|
||||
readonly strikethrough: this;
|
||||
|
||||
readonly visible: this;
|
||||
|
||||
readonly black: this;
|
||||
readonly red: this;
|
||||
readonly green: this;
|
||||
readonly yellow: this;
|
||||
readonly blue: this;
|
||||
readonly magenta: this;
|
||||
readonly cyan: this;
|
||||
readonly white: this;
|
||||
readonly gray: this;
|
||||
readonly grey: this;
|
||||
readonly blackBright: this;
|
||||
readonly redBright: this;
|
||||
readonly greenBright: this;
|
||||
readonly yellowBright: this;
|
||||
readonly blueBright: this;
|
||||
readonly magentaBright: this;
|
||||
readonly cyanBright: this;
|
||||
readonly whiteBright: this;
|
||||
|
||||
readonly bgBlack: this;
|
||||
readonly bgRed: this;
|
||||
readonly bgGreen: this;
|
||||
readonly bgYellow: this;
|
||||
readonly bgBlue: this;
|
||||
readonly bgMagenta: this;
|
||||
readonly bgCyan: this;
|
||||
readonly bgWhite: this;
|
||||
readonly bgBlackBright: this;
|
||||
readonly bgRedBright: this;
|
||||
readonly bgGreenBright: this;
|
||||
readonly bgYellowBright: this;
|
||||
readonly bgBlueBright: this;
|
||||
readonly bgMagentaBright: this;
|
||||
readonly bgCyanBright: this;
|
||||
readonly bgWhiteBright: this;
|
||||
}
|
||||
|
||||
declare const chalk: Chalk & { supportsColor: ColorSupport };
|
||||
|
||||
export default chalk
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
import chalk, {Level} from '..';
|
||||
|
||||
chalk.underline('foo');
|
||||
chalk.red('foo');
|
||||
chalk.bgRed('foo');
|
||||
|
||||
const name = 'Josh';
|
||||
chalk`Hello {bold.red ${name}}`;
|
||||
|
||||
chalk.red`foo`;
|
||||
chalk.underline`foo`;
|
||||
chalk`foo`;
|
||||
|
||||
chalk.red.bgGreen.underline('foo');
|
||||
chalk.underline.red.bgGreen('foo');
|
||||
|
||||
chalk.grey('foo');
|
||||
|
||||
chalk.constructor({level: 1});
|
||||
const ctx = chalk.constructor({level: Level.TrueColor });
|
||||
ctx('foo');
|
||||
ctx.red('foo');
|
||||
ctx`foo`;
|
||||
|
||||
chalk.enabled = true;
|
||||
chalk.level = 1;
|
||||
chalk.level = Level.Ansi256;
|
||||
|
||||
chalk.level === Level.Ansi256;
|
||||
|
||||
let chalkInstance = new chalk.constructor();
|
||||
chalkInstance = chalk.constructor();
|
||||
|
||||
chalkInstance.blue('foo');
|
||||
chalkInstance`foo`;
|
||||
|
||||
let x = 'imastring';
|
||||
x = chalk();
|
||||
|
||||
chalk.enabled;
|
||||
chalk.level;
|
||||
chalk.supportsColor.level;
|
||||
chalk.supportsColor.has16m;
|
||||
chalk.supportsColor.has256;
|
||||
chalk.supportsColor.hasBasic;
|
||||
|
||||
chalk.keyword('orange').bgBlue('foo');
|
||||
chalk.hex('#123456').bgBlue('foo');
|
||||
chalk.rgb(1, 14, 9).bgBlue('foo');
|
||||
chalk.hsl(1, 14, 9).bgBlue('foo');
|
||||
chalk.hsv(1, 14, 9).bgBlue('foo');
|
||||
chalk.hwb(1, 14, 9).bgBlue('foo');
|
||||
|
||||
chalk.visible('foo');
|
||||
chalk.red.visible('foo');
|
||||
chalk.visible.red('foo');
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noEmit": true,
|
||||
"allowJs": true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue