2021-11-26 16:34:27 +07:00
// TODO: Make it this when TS suports that.
2022-10-10 14:41:45 +08:00
// import {ModifierName as Modifiers, ForegroundColorName as ForegroundColor, BackgroundColorName as BackgroundColor, ColorName as Color} from '#ansi-styles';
2021-11-26 16:34:27 +07:00
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
2022-10-10 14:41:45 +08:00
import { ModifierName as Modifiers , ForegroundColorName as ForegroundColor , BackgroundColorName as BackgroundColor , ColorName as Color } from './vendor/ansi-styles/index.js' ;
2021-11-26 16:34:27 +07:00
import { ColorInfo , ColorSupportLevel } from './vendor/supports-color/index.js' ;
2021-11-21 19:51:24 +13:00
2021-04-16 15:23:29 +07:00
export interface Options {
2020-04-02 15:46:17 +08:00
/ * *
2021-04-16 15:23:29 +07:00
Specify the color support for Chalk .
By default , color support is automatically detected based on the environment .
2020-04-02 15:46:17 +08:00
Levels :
- ` 0 ` - All colors disabled .
- ` 1 ` - Basic 16 colors support .
- ` 2 ` - ANSI 256 colors support .
- ` 3 ` - Truecolor 16 million colors support .
* /
2021-04-16 15:23:29 +07:00
readonly level? : ColorSupportLevel ;
}
/ * *
Return a new Chalk instance .
* /
2021-11-21 19:51:24 +13:00
export const Chalk : new ( options? : Options ) = > ChalkInstance ; // eslint-disable-line @typescript-eslint/naming-convention
2021-04-16 15:23:29 +07:00
2021-11-10 22:12:33 +13:00
export interface ChalkInstance {
2021-04-16 15:23:29 +07:00
( . . . text : unknown [ ] ) : string ;
2019-04-28 04:10:44 +00:00
2018-12-26 03:06:00 +02:00
/ * *
2021-04-16 15:23:29 +07:00
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 .
2019-04-28 04:10:44 +00:00
* /
2021-04-16 15:23:29 +07:00
level : ColorSupportLevel ;
2019-04-28 04:10:44 +00:00
2021-04-22 15:54:42 +12:00
/ * *
Use RGB values to set text color .
2021-10-25 08:07:02 +13:00
@example
` ` `
import chalk from 'chalk' ;
chalk . rgb ( 222 , 173 , 237 ) ;
` ` `
2021-04-22 15:54:42 +12:00
* /
rgb : ( red : number , green : number , blue : number ) = > this ;
2021-04-16 15:23:29 +07:00
/ * *
Use HEX value to set text color .
2019-04-28 04:10:44 +00:00
2021-04-16 15:23:29 +07:00
@param color - Hexadecimal value representing the desired color .
2018-12-26 03:06:00 +02:00
2021-04-16 15:23:29 +07:00
@example
` ` `
import chalk from 'chalk' ;
2018-12-26 03:06:00 +02:00
2021-04-16 15:23:29 +07:00
chalk . hex ( '#DEADED' ) ;
` ` `
* /
2021-04-18 00:33:03 +12:00
hex : ( color : string ) = > this ;
2019-05-11 10:04:20 +02:00
2021-04-16 15:23:29 +07:00
/ * *
2021-04-22 15:54:42 +12:00
Use an [ 8 - bit unsigned number ] ( https : //en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
2021-10-25 08:07:02 +13:00
@example
` ` `
import chalk from 'chalk' ;
chalk . ansi256 ( 201 ) ;
` ` `
2021-04-16 15:23:29 +07:00
* /
2021-04-22 15:54:42 +12:00
ansi256 : ( index : number ) = > this ;
2020-04-02 15:46:17 +08:00
2021-04-16 15:23:29 +07:00
/ * *
2021-04-22 15:54:42 +12:00
Use RGB values to set background color .
2021-10-25 08:07:02 +13:00
@example
` ` `
import chalk from 'chalk' ;
chalk . bgRgb ( 222 , 173 , 237 ) ;
` ` `
2021-04-16 15:23:29 +07:00
* /
2021-04-22 15:54:42 +12:00
bgRgb : ( red : number , green : number , blue : number ) = > this ;
2019-04-28 04:10:44 +00:00
2021-04-16 15:23:29 +07:00
/ * *
Use HEX value to set background color .
2019-04-28 04:10:44 +00:00
2021-04-16 15:23:29 +07:00
@param color - Hexadecimal value representing the desired color .
2019-04-28 04:10:44 +00:00
2021-04-16 15:23:29 +07:00
@example
` ` `
import chalk from 'chalk' ;
2019-04-28 04:10:44 +00:00
2021-04-16 15:23:29 +07:00
chalk . bgHex ( '#DEADED' ) ;
` ` `
* /
2021-04-18 00:33:03 +12:00
bgHex : ( color : string ) = > this ;
2019-04-28 04:10:44 +00:00
2021-04-16 15:23:29 +07:00
/ * *
Use a [ 8 - bit unsigned number ] ( https : //en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
2021-10-25 08:07:02 +13:00
@example
` ` `
import chalk from 'chalk' ;
chalk . bgAnsi256 ( 201 ) ;
` ` `
2021-04-16 15:23:29 +07:00
* /
2021-04-18 00:33:03 +12:00
bgAnsi256 : ( index : number ) = > this ;
2021-04-16 15:23:29 +07:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Reset the current style .
2021-04-16 15:23:29 +07:00
* /
2021-04-18 00:33:03 +12:00
readonly reset : this ;
2021-04-16 15:23:29 +07:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Make the text bold .
2021-04-16 15:23:29 +07:00
* /
2021-04-18 00:33:03 +12:00
readonly bold : this ;
2021-04-16 15:23:29 +07:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Make the text have lower opacity .
2021-04-16 15:23:29 +07:00
* /
2021-04-18 00:33:03 +12:00
readonly dim : this ;
2021-04-16 15:23:29 +07:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Make the text italic . * ( Not widely supported ) *
2021-04-16 15:23:29 +07:00
* /
2021-04-18 00:33:03 +12:00
readonly italic : this ;
2021-04-16 15:23:29 +07:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Put a horizontal line below the text . * ( Not widely supported ) *
2021-04-16 15:23:29 +07:00
* /
2021-04-18 00:33:03 +12:00
readonly underline : this ;
2021-04-16 15:23:29 +07:00
2021-04-22 15:54:42 +12:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Put a horizontal line above the text . * ( Not widely supported ) *
2021-04-22 15:54:42 +12:00
* /
readonly overline : this ;
2021-04-16 15:23:29 +07:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Invert background and foreground colors .
2021-04-16 15:23:29 +07:00
* /
2021-04-18 00:33:03 +12:00
readonly inverse : this ;
2021-04-16 15:23:29 +07:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Print the text but make it invisible .
2021-04-16 15:23:29 +07:00
* /
2021-04-18 00:33:03 +12:00
readonly hidden : this ;
2021-04-16 15:23:29 +07:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Puts a horizontal line through the center of the text . * ( Not widely supported ) *
2021-04-16 15:23:29 +07:00
* /
2021-04-18 00:33:03 +12:00
readonly strikethrough : this ;
2021-04-16 15:23:29 +07:00
/ * *
2021-08-11 15:01:41 +02:00
Modifier : Print the text only when Chalk has a color level above zero .
2021-04-16 15:23:29 +07:00
Can be useful for things that are purely cosmetic .
* /
2021-04-18 00:33:03 +12:00
readonly visible : this ;
2021-04-16 15:23:29 +07:00
2021-04-18 00:33:03 +12:00
readonly black : this ;
readonly red : this ;
readonly green : this ;
readonly yellow : this ;
readonly blue : this ;
readonly magenta : this ;
readonly cyan : this ;
readonly white : this ;
2021-04-16 15:23:29 +07:00
/ *
Alias for ` blackBright ` .
* /
2021-04-18 00:33:03 +12:00
readonly gray : this ;
2021-04-16 15:23:29 +07:00
/ *
Alias for ` blackBright ` .
* /
2021-04-18 00:33:03 +12:00
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 ;
2021-04-16 15:23:29 +07:00
/ *
Alias for ` bgBlackBright ` .
* /
2021-04-18 00:33:03 +12:00
readonly bgGray : this ;
2021-04-16 15:23:29 +07:00
/ *
Alias for ` bgBlackBright ` .
* /
2021-04-18 00:33:03 +12:00
readonly bgGrey : this ;
2021-04-16 15:23:29 +07:00
2021-04-18 00:33:03 +12:00
readonly bgBlackBright : this ;
readonly bgRedBright : this ;
readonly bgGreenBright : this ;
readonly bgYellowBright : this ;
readonly bgBlueBright : this ;
readonly bgMagentaBright : this ;
readonly bgCyanBright : this ;
readonly bgWhiteBright : this ;
2018-12-26 03:06:00 +02:00
}
/ * *
2019-04-28 04:10:44 +00:00
Main Chalk object that allows to chain styles together .
2021-04-16 15:23:29 +07:00
2019-04-28 04:10:44 +00:00
Call the last one as a method with a string argument .
2021-04-16 15:23:29 +07:00
2019-04-28 04:10:44 +00:00
Order doesn ' t matter , and later styles take precedent in case of a conflict .
2021-04-16 15:23:29 +07:00
2019-04-28 04:10:44 +00:00
This simply means that ` chalk.red.yellow.green ` is equivalent to ` chalk.green ` .
* /
2021-11-10 22:12:33 +13:00
declare const chalk : ChalkInstance ;
2021-04-18 00:33:03 +12:00
2021-11-21 19:51:24 +13:00
export const supportsColor : ColorInfo ;
2021-04-18 00:33:03 +12:00
export const chalkStderr : typeof chalk ;
export const supportsColorStderr : typeof supportsColor ;
2019-04-28 04:10:44 +00:00
2022-10-10 14:41:45 +08:00
export {
ModifierName as Modifiers ,
ForegroundColorName as ForegroundColor ,
BackgroundColorName as BackgroundColor ,
ColorName as Color ,
// } from '#ansi-styles';
} from './vendor/ansi-styles/index.js' ;
2021-11-21 19:51:24 +13:00
export {
ColorInfo ,
ColorSupport ,
ColorSupportLevel ,
2021-11-26 16:34:27 +07:00
// } from '#supports-color';
} from './vendor/supports-color/index.js' ;
2021-11-21 19:51:24 +13:00
2022-10-05 22:44:40 +08:00
export const modifiers : readonly Modifiers [ ] ;
export const foregroundColors : readonly ForegroundColor [ ] ;
export const backgroundColors : readonly BackgroundColor [ ] ;
export const colors : readonly Color [ ] ;
2021-04-16 15:23:29 +07:00
export default chalk ;