index.d.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. export interface CSPair { // eslint-disable-line @typescript-eslint/naming-convention
  2. /**
  3. The ANSI terminal control sequence for starting this style.
  4. */
  5. readonly open: string;
  6. /**
  7. The ANSI terminal control sequence for ending this style.
  8. */
  9. readonly close: string;
  10. }
  11. export interface ColorBase {
  12. /**
  13. The ANSI terminal control sequence for ending this color.
  14. */
  15. readonly close: string;
  16. ansi(code: number): string;
  17. ansi256(code: number): string;
  18. ansi16m(red: number, green: number, blue: number): string;
  19. }
  20. export interface Modifier {
  21. /**
  22. Resets the current color chain.
  23. */
  24. readonly reset: CSPair;
  25. /**
  26. Make text bold.
  27. */
  28. readonly bold: CSPair;
  29. /**
  30. Emitting only a small amount of light.
  31. */
  32. readonly dim: CSPair;
  33. /**
  34. Make text italic. (Not widely supported)
  35. */
  36. readonly italic: CSPair;
  37. /**
  38. Make text underline. (Not widely supported)
  39. */
  40. readonly underline: CSPair;
  41. /**
  42. Make text overline.
  43. Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.
  44. */
  45. readonly overline: CSPair;
  46. /**
  47. Inverse background and foreground colors.
  48. */
  49. readonly inverse: CSPair;
  50. /**
  51. Prints the text, but makes it invisible.
  52. */
  53. readonly hidden: CSPair;
  54. /**
  55. Puts a horizontal line through the center of the text. (Not widely supported)
  56. */
  57. readonly strikethrough: CSPair;
  58. }
  59. export interface ForegroundColor {
  60. readonly black: CSPair;
  61. readonly red: CSPair;
  62. readonly green: CSPair;
  63. readonly yellow: CSPair;
  64. readonly blue: CSPair;
  65. readonly cyan: CSPair;
  66. readonly magenta: CSPair;
  67. readonly white: CSPair;
  68. /**
  69. Alias for `blackBright`.
  70. */
  71. readonly gray: CSPair;
  72. /**
  73. Alias for `blackBright`.
  74. */
  75. readonly grey: CSPair;
  76. readonly blackBright: CSPair;
  77. readonly redBright: CSPair;
  78. readonly greenBright: CSPair;
  79. readonly yellowBright: CSPair;
  80. readonly blueBright: CSPair;
  81. readonly cyanBright: CSPair;
  82. readonly magentaBright: CSPair;
  83. readonly whiteBright: CSPair;
  84. }
  85. export interface BackgroundColor {
  86. readonly bgBlack: CSPair;
  87. readonly bgRed: CSPair;
  88. readonly bgGreen: CSPair;
  89. readonly bgYellow: CSPair;
  90. readonly bgBlue: CSPair;
  91. readonly bgCyan: CSPair;
  92. readonly bgMagenta: CSPair;
  93. readonly bgWhite: CSPair;
  94. /**
  95. Alias for `bgBlackBright`.
  96. */
  97. readonly bgGray: CSPair;
  98. /**
  99. Alias for `bgBlackBright`.
  100. */
  101. readonly bgGrey: CSPair;
  102. readonly bgBlackBright: CSPair;
  103. readonly bgRedBright: CSPair;
  104. readonly bgGreenBright: CSPair;
  105. readonly bgYellowBright: CSPair;
  106. readonly bgBlueBright: CSPair;
  107. readonly bgCyanBright: CSPair;
  108. readonly bgMagentaBright: CSPair;
  109. readonly bgWhiteBright: CSPair;
  110. }
  111. export interface ConvertColor {
  112. /**
  113. Convert from the RGB color space to the ANSI 256 color space.
  114. @param red - (`0...255`)
  115. @param green - (`0...255`)
  116. @param blue - (`0...255`)
  117. */
  118. rgbToAnsi256(red: number, green: number, blue: number): number;
  119. /**
  120. Convert from the RGB HEX color space to the RGB color space.
  121. @param hex - A hexadecimal string containing RGB data.
  122. */
  123. hexToRgb(hex: string): [red: number, green: number, blue: number];
  124. /**
  125. Convert from the RGB HEX color space to the ANSI 256 color space.
  126. @param hex - A hexadecimal string containing RGB data.
  127. */
  128. hexToAnsi256(hex: string): number;
  129. /**
  130. Convert from the ANSI 256 color space to the ANSI 16 color space.
  131. @param code - A number representing the ANSI 256 color.
  132. */
  133. ansi256ToAnsi(code: number): number;
  134. /**
  135. Convert from the RGB color space to the ANSI 16 color space.
  136. @param red - (`0...255`)
  137. @param green - (`0...255`)
  138. @param blue - (`0...255`)
  139. */
  140. rgbToAnsi(red: number, green: number, blue: number): number;
  141. /**
  142. Convert from the RGB HEX color space to the ANSI 16 color space.
  143. @param hex - A hexadecimal string containing RGB data.
  144. */
  145. hexToAnsi(hex: string): number;
  146. }
  147. /**
  148. Basic modifier names.
  149. */
  150. export type ModifierName = keyof Modifier;
  151. /**
  152. Basic foreground color names.
  153. [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
  154. */
  155. export type ForegroundColorName = keyof ForegroundColor;
  156. /**
  157. Basic background color names.
  158. [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
  159. */
  160. export type BackgroundColorName = keyof BackgroundColor;
  161. /**
  162. Basic color names. The combination of foreground and background color names.
  163. [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
  164. */
  165. export type ColorName = ForegroundColorName | BackgroundColorName;
  166. /**
  167. Basic modifier names.
  168. */
  169. export const modifierNames: readonly ModifierName[];
  170. /**
  171. Basic foreground color names.
  172. */
  173. export const foregroundColorNames: readonly ForegroundColorName[];
  174. /**
  175. Basic background color names.
  176. */
  177. export const backgroundColorNames: readonly BackgroundColorName[];
  178. /*
  179. Basic color names. The combination of foreground and background color names.
  180. */
  181. export const colorNames: readonly ColorName[];
  182. declare const ansiStyles: {
  183. readonly modifier: Modifier;
  184. readonly color: ColorBase & ForegroundColor;
  185. readonly bgColor: ColorBase & BackgroundColor;
  186. readonly codes: ReadonlyMap<number, number>;
  187. } & ForegroundColor & BackgroundColor & Modifier & ConvertColor;
  188. export default ansiStyles;