index.d.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /**
  2. Basic foreground colors.
  3. [More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
  4. */
  5. declare type ForegroundColor =
  6. | 'black'
  7. | 'red'
  8. | 'green'
  9. | 'yellow'
  10. | 'blue'
  11. | 'magenta'
  12. | 'cyan'
  13. | 'white'
  14. | 'gray'
  15. | 'grey'
  16. | 'blackBright'
  17. | 'redBright'
  18. | 'greenBright'
  19. | 'yellowBright'
  20. | 'blueBright'
  21. | 'magentaBright'
  22. | 'cyanBright'
  23. | 'whiteBright';
  24. /**
  25. Basic background colors.
  26. [More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
  27. */
  28. declare type BackgroundColor =
  29. | 'bgBlack'
  30. | 'bgRed'
  31. | 'bgGreen'
  32. | 'bgYellow'
  33. | 'bgBlue'
  34. | 'bgMagenta'
  35. | 'bgCyan'
  36. | 'bgWhite'
  37. | 'bgGray'
  38. | 'bgGrey'
  39. | 'bgBlackBright'
  40. | 'bgRedBright'
  41. | 'bgGreenBright'
  42. | 'bgYellowBright'
  43. | 'bgBlueBright'
  44. | 'bgMagentaBright'
  45. | 'bgCyanBright'
  46. | 'bgWhiteBright';
  47. /**
  48. Basic colors.
  49. [More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
  50. */
  51. declare type Color = ForegroundColor | BackgroundColor;
  52. declare type Modifiers =
  53. | 'reset'
  54. | 'bold'
  55. | 'dim'
  56. | 'italic'
  57. | 'underline'
  58. | 'inverse'
  59. | 'hidden'
  60. | 'strikethrough'
  61. | 'visible';
  62. declare namespace chalk {
  63. /**
  64. Levels:
  65. - `0` - All colors disabled.
  66. - `1` - Basic 16 colors support.
  67. - `2` - ANSI 256 colors support.
  68. - `3` - Truecolor 16 million colors support.
  69. */
  70. type Level = 0 | 1 | 2 | 3;
  71. interface Options {
  72. /**
  73. Specify the color support for Chalk.
  74. By default, color support is automatically detected based on the environment.
  75. Levels:
  76. - `0` - All colors disabled.
  77. - `1` - Basic 16 colors support.
  78. - `2` - ANSI 256 colors support.
  79. - `3` - Truecolor 16 million colors support.
  80. */
  81. level?: Level;
  82. }
  83. /**
  84. Return a new Chalk instance.
  85. */
  86. type Instance = new (options?: Options) => Chalk;
  87. /**
  88. Detect whether the terminal supports color.
  89. */
  90. interface ColorSupport {
  91. /**
  92. The color level used by Chalk.
  93. */
  94. level: Level;
  95. /**
  96. Return whether Chalk supports basic 16 colors.
  97. */
  98. hasBasic: boolean;
  99. /**
  100. Return whether Chalk supports ANSI 256 colors.
  101. */
  102. has256: boolean;
  103. /**
  104. Return whether Chalk supports Truecolor 16 million colors.
  105. */
  106. has16m: boolean;
  107. }
  108. interface ChalkFunction {
  109. /**
  110. Use a template string.
  111. @remarks Template literals are unsupported for nested calls (see [issue #341](https://github.com/chalk/chalk/issues/341))
  112. @example
  113. ```
  114. import chalk = require('chalk');
  115. log(chalk`
  116. CPU: {red ${cpu.totalPercent}%}
  117. RAM: {green ${ram.used / ram.total * 100}%}
  118. DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
  119. `);
  120. ```
  121. @example
  122. ```
  123. import chalk = require('chalk');
  124. log(chalk.red.bgBlack`2 + 3 = {bold ${2 + 3}}`)
  125. ```
  126. */
  127. (text: TemplateStringsArray, ...placeholders: unknown[]): string;
  128. (...text: unknown[]): string;
  129. }
  130. interface Chalk extends ChalkFunction {
  131. /**
  132. Return a new Chalk instance.
  133. */
  134. Instance: Instance;
  135. /**
  136. The color support for Chalk.
  137. By default, color support is automatically detected based on the environment.
  138. Levels:
  139. - `0` - All colors disabled.
  140. - `1` - Basic 16 colors support.
  141. - `2` - ANSI 256 colors support.
  142. - `3` - Truecolor 16 million colors support.
  143. */
  144. level: Level;
  145. /**
  146. Use HEX value to set text color.
  147. @param color - Hexadecimal value representing the desired color.
  148. @example
  149. ```
  150. import chalk = require('chalk');
  151. chalk.hex('#DEADED');
  152. ```
  153. */
  154. hex(color: string): Chalk;
  155. /**
  156. Use keyword color value to set text color.
  157. @param color - Keyword value representing the desired color.
  158. @example
  159. ```
  160. import chalk = require('chalk');
  161. chalk.keyword('orange');
  162. ```
  163. */
  164. keyword(color: string): Chalk;
  165. /**
  166. Use RGB values to set text color.
  167. */
  168. rgb(red: number, green: number, blue: number): Chalk;
  169. /**
  170. Use HSL values to set text color.
  171. */
  172. hsl(hue: number, saturation: number, lightness: number): Chalk;
  173. /**
  174. Use HSV values to set text color.
  175. */
  176. hsv(hue: number, saturation: number, value: number): Chalk;
  177. /**
  178. Use HWB values to set text color.
  179. */
  180. hwb(hue: number, whiteness: number, blackness: number): Chalk;
  181. /**
  182. Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
  183. 30 <= code && code < 38 || 90 <= code && code < 98
  184. For example, 31 for red, 91 for redBright.
  185. */
  186. ansi(code: number): Chalk;
  187. /**
  188. Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
  189. */
  190. ansi256(index: number): Chalk;
  191. /**
  192. Use HEX value to set background color.
  193. @param color - Hexadecimal value representing the desired color.
  194. @example
  195. ```
  196. import chalk = require('chalk');
  197. chalk.bgHex('#DEADED');
  198. ```
  199. */
  200. bgHex(color: string): Chalk;
  201. /**
  202. Use keyword color value to set background color.
  203. @param color - Keyword value representing the desired color.
  204. @example
  205. ```
  206. import chalk = require('chalk');
  207. chalk.bgKeyword('orange');
  208. ```
  209. */
  210. bgKeyword(color: string): Chalk;
  211. /**
  212. Use RGB values to set background color.
  213. */
  214. bgRgb(red: number, green: number, blue: number): Chalk;
  215. /**
  216. Use HSL values to set background color.
  217. */
  218. bgHsl(hue: number, saturation: number, lightness: number): Chalk;
  219. /**
  220. Use HSV values to set background color.
  221. */
  222. bgHsv(hue: number, saturation: number, value: number): Chalk;
  223. /**
  224. Use HWB values to set background color.
  225. */
  226. bgHwb(hue: number, whiteness: number, blackness: number): Chalk;
  227. /**
  228. Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
  229. 30 <= code && code < 38 || 90 <= code && code < 98
  230. For example, 31 for red, 91 for redBright.
  231. Use the foreground code, not the background code (for example, not 41, nor 101).
  232. */
  233. bgAnsi(code: number): Chalk;
  234. /**
  235. Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
  236. */
  237. bgAnsi256(index: number): Chalk;
  238. /**
  239. Modifier: Resets the current color chain.
  240. */
  241. readonly reset: Chalk;
  242. /**
  243. Modifier: Make text bold.
  244. */
  245. readonly bold: Chalk;
  246. /**
  247. Modifier: Emitting only a small amount of light.
  248. */
  249. readonly dim: Chalk;
  250. /**
  251. Modifier: Make text italic. (Not widely supported)
  252. */
  253. readonly italic: Chalk;
  254. /**
  255. Modifier: Make text underline. (Not widely supported)
  256. */
  257. readonly underline: Chalk;
  258. /**
  259. Modifier: Inverse background and foreground colors.
  260. */
  261. readonly inverse: Chalk;
  262. /**
  263. Modifier: Prints the text, but makes it invisible.
  264. */
  265. readonly hidden: Chalk;
  266. /**
  267. Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
  268. */
  269. readonly strikethrough: Chalk;
  270. /**
  271. Modifier: Prints the text only when Chalk has a color support level > 0.
  272. Can be useful for things that are purely cosmetic.
  273. */
  274. readonly visible: Chalk;
  275. readonly black: Chalk;
  276. readonly red: Chalk;
  277. readonly green: Chalk;
  278. readonly yellow: Chalk;
  279. readonly blue: Chalk;
  280. readonly magenta: Chalk;
  281. readonly cyan: Chalk;
  282. readonly white: Chalk;
  283. /*
  284. Alias for `blackBright`.
  285. */
  286. readonly gray: Chalk;
  287. /*
  288. Alias for `blackBright`.
  289. */
  290. readonly grey: Chalk;
  291. readonly blackBright: Chalk;
  292. readonly redBright: Chalk;
  293. readonly greenBright: Chalk;
  294. readonly yellowBright: Chalk;
  295. readonly blueBright: Chalk;
  296. readonly magentaBright: Chalk;
  297. readonly cyanBright: Chalk;
  298. readonly whiteBright: Chalk;
  299. readonly bgBlack: Chalk;
  300. readonly bgRed: Chalk;
  301. readonly bgGreen: Chalk;
  302. readonly bgYellow: Chalk;
  303. readonly bgBlue: Chalk;
  304. readonly bgMagenta: Chalk;
  305. readonly bgCyan: Chalk;
  306. readonly bgWhite: Chalk;
  307. /*
  308. Alias for `bgBlackBright`.
  309. */
  310. readonly bgGray: Chalk;
  311. /*
  312. Alias for `bgBlackBright`.
  313. */
  314. readonly bgGrey: Chalk;
  315. readonly bgBlackBright: Chalk;
  316. readonly bgRedBright: Chalk;
  317. readonly bgGreenBright: Chalk;
  318. readonly bgYellowBright: Chalk;
  319. readonly bgBlueBright: Chalk;
  320. readonly bgMagentaBright: Chalk;
  321. readonly bgCyanBright: Chalk;
  322. readonly bgWhiteBright: Chalk;
  323. }
  324. }
  325. /**
  326. Main Chalk object that allows to chain styles together.
  327. Call the last one as a method with a string argument.
  328. Order doesn't matter, and later styles take precedent in case of a conflict.
  329. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
  330. */
  331. declare const chalk: chalk.Chalk & chalk.ChalkFunction & {
  332. supportsColor: chalk.ColorSupport | false;
  333. Level: chalk.Level;
  334. Color: Color;
  335. ForegroundColor: ForegroundColor;
  336. BackgroundColor: BackgroundColor;
  337. Modifiers: Modifiers;
  338. stderr: chalk.Chalk & {supportsColor: chalk.ColorSupport | false};
  339. };
  340. export = chalk;