index.d.ts 5.4 KB

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