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