Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

409 lines
8.6KB

  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. */
  122. (text: TemplateStringsArray, ...placeholders: unknown[]): string;
  123. (...text: unknown[]): string;
  124. }
  125. interface Chalk extends ChalkFunction {
  126. /**
  127. Return a new Chalk instance.
  128. */
  129. Instance: Instance;
  130. /**
  131. The color support for Chalk.
  132. By default, color support is automatically detected based on the environment.
  133. Levels:
  134. - `0` - All colors disabled.
  135. - `1` - Basic 16 colors support.
  136. - `2` - ANSI 256 colors support.
  137. - `3` - Truecolor 16 million colors support.
  138. */
  139. level: Level;
  140. /**
  141. Use HEX value to set text color.
  142. @param color - Hexadecimal value representing the desired color.
  143. @example
  144. ```
  145. import chalk = require('chalk');
  146. chalk.hex('#DEADED');
  147. ```
  148. */
  149. hex(color: string): Chalk;
  150. /**
  151. Use keyword color value to set text color.
  152. @param color - Keyword value representing the desired color.
  153. @example
  154. ```
  155. import chalk = require('chalk');
  156. chalk.keyword('orange');
  157. ```
  158. */
  159. keyword(color: string): Chalk;
  160. /**
  161. Use RGB values to set text color.
  162. */
  163. rgb(red: number, green: number, blue: number): Chalk;
  164. /**
  165. Use HSL values to set text color.
  166. */
  167. hsl(hue: number, saturation: number, lightness: number): Chalk;
  168. /**
  169. Use HSV values to set text color.
  170. */
  171. hsv(hue: number, saturation: number, value: number): Chalk;
  172. /**
  173. Use HWB values to set text color.
  174. */
  175. hwb(hue: number, whiteness: number, blackness: number): Chalk;
  176. /**
  177. 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.
  178. 30 <= code && code < 38 || 90 <= code && code < 98
  179. For example, 31 for red, 91 for redBright.
  180. */
  181. ansi(code: number): Chalk;
  182. /**
  183. Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
  184. */
  185. ansi256(index: number): Chalk;
  186. /**
  187. Use HEX value to set background color.
  188. @param color - Hexadecimal value representing the desired color.
  189. @example
  190. ```
  191. import chalk = require('chalk');
  192. chalk.bgHex('#DEADED');
  193. ```
  194. */
  195. bgHex(color: string): Chalk;
  196. /**
  197. Use keyword color value to set background color.
  198. @param color - Keyword value representing the desired color.
  199. @example
  200. ```
  201. import chalk = require('chalk');
  202. chalk.bgKeyword('orange');
  203. ```
  204. */
  205. bgKeyword(color: string): Chalk;
  206. /**
  207. Use RGB values to set background color.
  208. */
  209. bgRgb(red: number, green: number, blue: number): Chalk;
  210. /**
  211. Use HSL values to set background color.
  212. */
  213. bgHsl(hue: number, saturation: number, lightness: number): Chalk;
  214. /**
  215. Use HSV values to set background color.
  216. */
  217. bgHsv(hue: number, saturation: number, value: number): Chalk;
  218. /**
  219. Use HWB values to set background color.
  220. */
  221. bgHwb(hue: number, whiteness: number, blackness: number): Chalk;
  222. /**
  223. 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.
  224. 30 <= code && code < 38 || 90 <= code && code < 98
  225. For example, 31 for red, 91 for redBright.
  226. Use the foreground code, not the background code (for example, not 41, nor 101).
  227. */
  228. bgAnsi(code: number): Chalk;
  229. /**
  230. Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
  231. */
  232. bgAnsi256(index: number): Chalk;
  233. /**
  234. Modifier: Resets the current color chain.
  235. */
  236. readonly reset: Chalk;
  237. /**
  238. Modifier: Make text bold.
  239. */
  240. readonly bold: Chalk;
  241. /**
  242. Modifier: Emitting only a small amount of light.
  243. */
  244. readonly dim: Chalk;
  245. /**
  246. Modifier: Make text italic. (Not widely supported)
  247. */
  248. readonly italic: Chalk;
  249. /**
  250. Modifier: Make text underline. (Not widely supported)
  251. */
  252. readonly underline: Chalk;
  253. /**
  254. Modifier: Inverse background and foreground colors.
  255. */
  256. readonly inverse: Chalk;
  257. /**
  258. Modifier: Prints the text, but makes it invisible.
  259. */
  260. readonly hidden: Chalk;
  261. /**
  262. Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
  263. */
  264. readonly strikethrough: Chalk;
  265. /**
  266. Modifier: Prints the text only when Chalk has a color support level > 0.
  267. Can be useful for things that are purely cosmetic.
  268. */
  269. readonly visible: Chalk;
  270. readonly black: Chalk;
  271. readonly red: Chalk;
  272. readonly green: Chalk;
  273. readonly yellow: Chalk;
  274. readonly blue: Chalk;
  275. readonly magenta: Chalk;
  276. readonly cyan: Chalk;
  277. readonly white: Chalk;
  278. /*
  279. Alias for `blackBright`.
  280. */
  281. readonly gray: Chalk;
  282. /*
  283. Alias for `blackBright`.
  284. */
  285. readonly grey: Chalk;
  286. readonly blackBright: Chalk;
  287. readonly redBright: Chalk;
  288. readonly greenBright: Chalk;
  289. readonly yellowBright: Chalk;
  290. readonly blueBright: Chalk;
  291. readonly magentaBright: Chalk;
  292. readonly cyanBright: Chalk;
  293. readonly whiteBright: Chalk;
  294. readonly bgBlack: Chalk;
  295. readonly bgRed: Chalk;
  296. readonly bgGreen: Chalk;
  297. readonly bgYellow: Chalk;
  298. readonly bgBlue: Chalk;
  299. readonly bgMagenta: Chalk;
  300. readonly bgCyan: Chalk;
  301. readonly bgWhite: Chalk;
  302. /*
  303. Alias for `bgBlackBright`.
  304. */
  305. readonly bgGray: Chalk;
  306. /*
  307. Alias for `bgBlackBright`.
  308. */
  309. readonly bgGrey: Chalk;
  310. readonly bgBlackBright: Chalk;
  311. readonly bgRedBright: Chalk;
  312. readonly bgGreenBright: Chalk;
  313. readonly bgYellowBright: Chalk;
  314. readonly bgBlueBright: Chalk;
  315. readonly bgMagentaBright: Chalk;
  316. readonly bgCyanBright: Chalk;
  317. readonly bgWhiteBright: Chalk;
  318. }
  319. }
  320. /**
  321. Main Chalk object that allows to chain styles together.
  322. Call the last one as a method with a string argument.
  323. Order doesn't matter, and later styles take precedent in case of a conflict.
  324. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
  325. */
  326. declare const chalk: chalk.Chalk & chalk.ChalkFunction & {
  327. supportsColor: chalk.ColorSupport | false;
  328. Level: chalk.Level;
  329. Color: Color;
  330. ForegroundColor: ForegroundColor;
  331. BackgroundColor: BackgroundColor;
  332. Modifiers: Modifiers;
  333. stderr: chalk.Chalk & {supportsColor: chalk.ColorSupport | false};
  334. };
  335. export = chalk;