Urara-Blog/node_modules/.pnpm-store/v3/files/33/00103c6f1c47d7d3ee570f2d9e82e56b1a1620d0178f5af5c4169628c95984f8b1672e72e1116ea487901cab19dfffd9c2116273d600395e1260b26c189727
2022-08-14 01:14:53 +08:00

121 lines
No EOL
3.9 KiB
Text

let enabled = true;
// Support both browser and node environments
const globalVar = typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: {};
/**
* Detect how much colors the current terminal supports
*/
let supportLevel = 0 /* none */;
if (globalVar.process && globalVar.process.env && globalVar.process.stdout) {
const { FORCE_COLOR, NODE_DISABLE_COLORS, TERM } = globalVar.process.env;
if (NODE_DISABLE_COLORS || FORCE_COLOR === '0') {
enabled = false;
}
else if (FORCE_COLOR === '1') {
enabled = true;
}
else if (TERM === 'dumb') {
enabled = false;
}
else if ('CI' in globalVar.process.env &&
[
'TRAVIS',
'CIRCLECI',
'APPVEYOR',
'GITLAB_CI',
'GITHUB_ACTIONS',
'BUILDKITE',
'DRONE',
].some(vendor => vendor in globalVar.process.env)) {
enabled = true;
}
else {
enabled = process.stdout.isTTY;
}
if (enabled) {
supportLevel =
TERM && TERM.endsWith('-256color')
? 2 /* ansi256 */
: 1 /* ansi */;
}
}
export let options = {
enabled,
supportLevel,
};
function kolorist(start, end, level = 1 /* ansi */) {
const open = `\x1b[${start}m`;
const close = `\x1b[${end}m`;
const regex = new RegExp(`\\x1b\\[${end}m`, 'g');
return (str) => {
return options.enabled && options.supportLevel >= level
? open + ('' + str).replace(regex, open) + close
: '' + str;
};
}
export function stripColors(str) {
return ('' + str)
.replace(/\x1b\[[0-9;]+m/g, '')
.replace(/\x1b\]8;;.*?\x07(.*?)\x1b\]8;;\x07/g, (_, group) => group);
}
// modifiers
export const reset = kolorist(0, 0);
export const bold = kolorist(1, 22);
export const dim = kolorist(2, 22);
export const italic = kolorist(3, 23);
export const underline = kolorist(4, 24);
export const inverse = kolorist(7, 27);
export const hidden = kolorist(8, 28);
export const strikethrough = kolorist(9, 29);
// colors
export const black = kolorist(30, 39);
export const red = kolorist(31, 39);
export const green = kolorist(32, 39);
export const yellow = kolorist(33, 39);
export const blue = kolorist(34, 39);
export const magenta = kolorist(35, 39);
export const cyan = kolorist(36, 39);
export const white = kolorist(97, 39);
export const gray = kolorist(90, 39);
export const lightGray = kolorist(37, 39);
export const lightRed = kolorist(91, 39);
export const lightGreen = kolorist(92, 39);
export const lightYellow = kolorist(93, 39);
export const lightBlue = kolorist(94, 39);
export const lightMagenta = kolorist(95, 39);
export const lightCyan = kolorist(96, 39);
// background colors
export const bgBlack = kolorist(40, 49);
export const bgRed = kolorist(41, 49);
export const bgGreen = kolorist(42, 49);
export const bgYellow = kolorist(43, 49);
export const bgBlue = kolorist(44, 49);
export const bgMagenta = kolorist(45, 49);
export const bgCyan = kolorist(46, 49);
export const bgWhite = kolorist(107, 49);
export const bgGray = kolorist(100, 49);
export const bgLightRed = kolorist(101, 49);
export const bgLightGreen = kolorist(102, 49);
export const bgLightYellow = kolorist(103, 49);
export const bgLightBlue = kolorist(104, 49);
export const bgLightMagenta = kolorist(105, 49);
export const bgLightCyan = kolorist(106, 49);
export const bgLightGray = kolorist(47, 49);
// 256 support
export const ansi256 = (n) => kolorist('38;5;' + n, 0, 2 /* ansi256 */);
export const ansi256Bg = (n) => kolorist('48;5;' + n, 0, 2 /* ansi256 */);
// Links
const OSC = '\u001B]';
const BEL = '\u0007';
const SEP = ';';
export function link(text, url) {
return options.enabled
? OSC + '8' + SEP + SEP + url + BEL + text + OSC + '8' + SEP + SEP + BEL
: `${text} (\u200B${url}\u200B)`;
}
//# sourceMappingURL=index.js.map