base.d.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. // From https://github.com/sindresorhus/type-fest
  2. type Primitive =
  3. | null // eslint-disable-line @typescript-eslint/ban-types
  4. | undefined
  5. | string
  6. | number
  7. | boolean
  8. | symbol
  9. | bigint;
  10. type LiteralUnion<LiteralType, BaseType extends Primitive> =
  11. | LiteralType
  12. | (BaseType & Record<never, never>);
  13. // -
  14. export type ImageOptions = {
  15. /**
  16. The width is given as a number followed by a unit, or the word `'auto'`.
  17. - `N`: N character cells.
  18. - `Npx`: N pixels.
  19. - `N%`: N percent of the session's width or height.
  20. - `auto`: The image's inherent size will be used to determine an appropriate dimension.
  21. */
  22. readonly width?: LiteralUnion<'auto', number | string>;
  23. /**
  24. The height is given as a number followed by a unit, or the word `'auto'`.
  25. - `N`: N character cells.
  26. - `Npx`: N pixels.
  27. - `N%`: N percent of the session's width or height.
  28. - `auto`: The image's inherent size will be used to determine an appropriate dimension.
  29. */
  30. readonly height?: LiteralUnion<'auto', number | string>;
  31. /**
  32. @default true
  33. */
  34. readonly preserveAspectRatio?: boolean;
  35. };
  36. export type AnnotationOptions = {
  37. /**
  38. Nonzero number of columns to annotate.
  39. Default: The remainder of the line.
  40. */
  41. readonly length?: number;
  42. /**
  43. Starting X coordinate.
  44. Must be used with `y` and `length`.
  45. Default: The cursor position
  46. */
  47. readonly x?: number;
  48. /**
  49. Starting Y coordinate.
  50. Must be used with `x` and `length`.
  51. Default: Cursor position.
  52. */
  53. readonly y?: number;
  54. /**
  55. Create a "hidden" annotation.
  56. Annotations created this way can be shown using the "Show Annotations" iTerm command.
  57. */
  58. readonly isHidden?: boolean;
  59. };
  60. /**
  61. Set the absolute position of the cursor. `x0` `y0` is the top left of the screen.
  62. */
  63. export function cursorTo(x: number, y?: number): string;
  64. /**
  65. Set the position of the cursor relative to its current position.
  66. */
  67. export function cursorMove(x: number, y?: number): string;
  68. /**
  69. Move cursor up a specific amount of rows.
  70. @param count - Count of rows to move up. Default is `1`.
  71. */
  72. export function cursorUp(count?: number): string;
  73. /**
  74. Move cursor down a specific amount of rows.
  75. @param count - Count of rows to move down. Default is `1`.
  76. */
  77. export function cursorDown(count?: number): string;
  78. /**
  79. Move cursor forward a specific amount of rows.
  80. @param count - Count of rows to move forward. Default is `1`.
  81. */
  82. export function cursorForward(count?: number): string;
  83. /**
  84. Move cursor backward a specific amount of rows.
  85. @param count - Count of rows to move backward. Default is `1`.
  86. */
  87. export function cursorBackward(count?: number): string;
  88. /**
  89. Move cursor to the left side.
  90. */
  91. export const cursorLeft: string;
  92. /**
  93. Save cursor position.
  94. */
  95. export const cursorSavePosition: string;
  96. /**
  97. Restore saved cursor position.
  98. */
  99. export const cursorRestorePosition: string;
  100. /**
  101. Get cursor position.
  102. */
  103. export const cursorGetPosition: string;
  104. /**
  105. Move cursor to the next line.
  106. */
  107. export const cursorNextLine: string;
  108. /**
  109. Move cursor to the previous line.
  110. */
  111. export const cursorPrevLine: string;
  112. /**
  113. Hide cursor.
  114. */
  115. export const cursorHide: string;
  116. /**
  117. Show cursor.
  118. */
  119. export const cursorShow: string;
  120. /**
  121. Erase from the current cursor position up the specified amount of rows.
  122. @param count - Count of rows to erase.
  123. */
  124. export function eraseLines(count: number): string;
  125. /**
  126. Erase from the current cursor position to the end of the current line.
  127. */
  128. export const eraseEndLine: string;
  129. /**
  130. Erase from the current cursor position to the start of the current line.
  131. */
  132. export const eraseStartLine: string;
  133. /**
  134. Erase the entire current line.
  135. */
  136. export const eraseLine: string;
  137. /**
  138. Erase the screen from the current line down to the bottom of the screen.
  139. */
  140. export const eraseDown: string;
  141. /**
  142. Erase the screen from the current line up to the top of the screen.
  143. */
  144. export const eraseUp: string;
  145. /**
  146. Erase the screen and move the cursor the top left position.
  147. */
  148. export const eraseScreen: string;
  149. /**
  150. Scroll display up one line.
  151. */
  152. export const scrollUp: string;
  153. /**
  154. Scroll display down one line.
  155. */
  156. export const scrollDown: string;
  157. /**
  158. Clear the terminal screen. (Viewport)
  159. */
  160. export const clearScreen: string;
  161. /**
  162. Clear the whole terminal, including scrollback buffer. (Not just the visible part of it)
  163. */
  164. export const clearTerminal: string;
  165. /**
  166. Enter the [alternative screen](https://terminalguide.namepad.de/mode/p47/).
  167. */
  168. export const enterAlternativeScreen: string;
  169. /**
  170. Exit the [alternative screen](https://terminalguide.namepad.de/mode/p47/), assuming `enterAlternativeScreen` was called before.
  171. */
  172. export const exitAlternativeScreen: string;
  173. /**
  174. Output a beeping sound.
  175. */
  176. export const beep: string;
  177. /**
  178. Create a clickable link.
  179. [Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) Use [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks) to detect link support.
  180. */
  181. export function link(text: string, url: string): string;
  182. /**
  183. Display an image.
  184. See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module.
  185. @param data - Image data. Usually read in with `fs.readFile()`.
  186. */
  187. export function image(data: Uint8Array, options?: ImageOptions): string;
  188. export const iTerm: {
  189. /**
  190. [Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click).
  191. @param cwd - Current directory. Default: `process.cwd()`.
  192. */
  193. setCwd(cwd?: string): string,
  194. /**
  195. An annotation looks like this when shown:
  196. ![screenshot of iTerm annotation](https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png)
  197. See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information.
  198. @param message - The message to display within the annotation. The `|` character is disallowed and will be stripped.
  199. @returns An escape code which will create an annotation when printed in iTerm2.
  200. */
  201. annotation(message: string, options?: AnnotationOptions): string
  202. };