UNPKG

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