index.d.ts 8.4 KB

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