提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
5.1 KiB

  1. export type 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 type 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 type 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 type 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 type 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 type 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;