Sync code
This commit is contained in:
parent
ef53fde412
commit
79e9185fd6
5 changed files with 80 additions and 53 deletions
48
source/index.d.ts
vendored
48
source/index.d.ts
vendored
|
|
@ -1,45 +1,9 @@
|
|||
// TODO: Make it this when TS suports that.
|
||||
// import {ModifierName as Modifiers, ForegroundColorName as ForegroundColor, BackgroundColorName as BackgroundColor, ColorName as Color} from '#ansi-styles';
|
||||
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
|
||||
import {ModifierName as Modifiers, ForegroundColorName as ForegroundColor, BackgroundColorName as BackgroundColor, ColorName as Color} from './vendor/ansi-styles/index.js';
|
||||
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
|
||||
|
||||
type BasicColor = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
|
||||
type BrightColor = `${BasicColor}Bright`;
|
||||
type Grey = 'gray' | 'grey';
|
||||
|
||||
/**
|
||||
Basic foreground colors.
|
||||
|
||||
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
||||
*/
|
||||
|
||||
export type ForegroundColor = BasicColor | BrightColor | Grey;
|
||||
|
||||
/**
|
||||
Basic background colors.
|
||||
|
||||
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
||||
*/
|
||||
export type BackgroundColor = `bg${Capitalize<ForegroundColor>}`;
|
||||
|
||||
/**
|
||||
Basic colors.
|
||||
|
||||
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
||||
*/
|
||||
export type Color = ForegroundColor | BackgroundColor;
|
||||
|
||||
export type Modifiers =
|
||||
| 'reset'
|
||||
| 'bold'
|
||||
| 'dim'
|
||||
| 'italic'
|
||||
| 'underline'
|
||||
| 'overline'
|
||||
| 'inverse'
|
||||
| 'hidden'
|
||||
| 'strikethrough'
|
||||
| 'visible';
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
Specify the color support for Chalk.
|
||||
|
|
@ -277,6 +241,14 @@ export const supportsColor: ColorInfo;
|
|||
export const chalkStderr: typeof chalk;
|
||||
export const supportsColorStderr: typeof supportsColor;
|
||||
|
||||
export {
|
||||
ModifierName as Modifiers,
|
||||
ForegroundColorName as ForegroundColor,
|
||||
BackgroundColorName as BackgroundColor,
|
||||
ColorName as Color,
|
||||
// } from '#ansi-styles';
|
||||
} from './vendor/ansi-styles/index.js';
|
||||
|
||||
export {
|
||||
ColorInfo,
|
||||
ColorSupport,
|
||||
|
|
|
|||
|
|
@ -204,14 +204,16 @@ Object.defineProperties(createChalk.prototype, styles);
|
|||
const chalk = createChalk();
|
||||
export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});
|
||||
|
||||
export {
|
||||
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 const modifiers = Object.keys(ansiStyles.modifier);
|
||||
export const foregroundColors = Object.keys(ansiStyles.color);
|
||||
export const backgroundColors = Object.keys(ansiStyles.bgColor);
|
||||
export const colors = [...foregroundColors, ...backgroundColors];
|
||||
|
||||
export default chalk;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {expectType, expectAssignable, expectError} from 'tsd';
|
||||
import chalk, {Chalk, ChalkInstance, Color, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr} from './index.js';
|
||||
import chalk, {Chalk, ChalkInstance, Modifiers, ForegroundColor, BackgroundColor, Color, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr} from './index.js';
|
||||
|
||||
// - supportsColor -
|
||||
expectType<ColorInfo>(supportsColor);
|
||||
|
|
@ -141,6 +141,20 @@ 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}}`);
|
||||
|
||||
// -- Color types ==
|
||||
// -- Modifiers types
|
||||
expectAssignable<Modifiers>('strikethrough');
|
||||
expectError<Modifiers>('delete');
|
||||
|
||||
// -- Foreground types
|
||||
expectAssignable<ForegroundColor>('red');
|
||||
expectError<ForegroundColor>('pink');
|
||||
|
||||
// -- Background types
|
||||
expectAssignable<BackgroundColor>('bgRed');
|
||||
expectError<BackgroundColor>('bgPink');
|
||||
|
||||
// -- Color types --
|
||||
expectAssignable<Color>('red');
|
||||
expectAssignable<Color>('bgRed');
|
||||
expectError<Color>('hotpink');
|
||||
expectError<Color>('bgHotpink');
|
||||
|
|
|
|||
48
source/vendor/ansi-styles/index.d.ts
vendored
48
source/vendor/ansi-styles/index.d.ts
vendored
|
|
@ -180,6 +180,49 @@ export interface ConvertColor {
|
|||
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;
|
||||
|
|
@ -187,9 +230,4 @@ declare const ansiStyles: {
|
|||
readonly codes: ReadonlyMap<number, number>;
|
||||
} & ForegroundColor & BackgroundColor & Modifier & ConvertColor;
|
||||
|
||||
declare const modifiers: readonly Modifier[];
|
||||
declare const foregroundColors: readonly ForegroundColor[];
|
||||
declare const backgroundColors: readonly BackgroundColor[];
|
||||
declare const colors: readonly Color[];
|
||||
|
||||
export default ansiStyles;
|
||||
|
|
|
|||
7
source/vendor/ansi-styles/index.js
vendored
7
source/vendor/ansi-styles/index.js
vendored
|
|
@ -214,8 +214,9 @@ function assembleStyles() {
|
|||
}
|
||||
|
||||
const ansiStyles = assembleStyles();
|
||||
export const modifiers = Object.keys(styles.modifier);
|
||||
export const foregroundColors = Object.keys(styles.color);
|
||||
export const backgroundColors = Object.keys(styles.bgColor);
|
||||
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];
|
||||
|
||||
export default ansiStyles;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue