UNPKG

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