@xterm/headless 5.4.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1312 @@
1
+ /**
2
+ * @license MIT
3
+ *
4
+ * This contains the type declarations for the xterm.js library. Note that
5
+ * some interfaces differ between this file and the actual implementation in
6
+ * src/, that's because this file declares the *public* API which is intended
7
+ * to be stable and consumed by external programs.
8
+ */
9
+
10
+ declare module '@xterm/headless' {
11
+ /**
12
+ * A string representing log level.
13
+ */
14
+ export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off';
15
+
16
+ /**
17
+ * An object containing options for the terminal.
18
+ */
19
+ export interface ITerminalOptions {
20
+ /**
21
+ * Whether to allow the use of proposed API. When false, any usage of APIs
22
+ * marked as experimental/proposed will throw an error. The default is
23
+ * false.
24
+ */
25
+ allowProposedApi?: boolean;
26
+
27
+ /**
28
+ * Whether background should support non-opaque color. It must be set before
29
+ * executing the `Terminal.open()` method and can't be changed later without
30
+ * executing it again. Note that enabling this can negatively impact
31
+ * performance.
32
+ */
33
+ allowTransparency?: boolean;
34
+
35
+ /**
36
+ * If enabled, alt + click will move the prompt cursor to position
37
+ * underneath the mouse. The default is true.
38
+ */
39
+ altClickMovesCursor?: boolean;
40
+
41
+ /**
42
+ * When enabled the cursor will be set to the beginning of the next line
43
+ * with every new line. This is equivalent to sending '\r\n' for each '\n'.
44
+ * Normally the termios settings of the underlying PTY deals with the
45
+ * translation of '\n' to '\r\n' and this setting should not be used. If you
46
+ * deal with data from a non-PTY related source, this settings might be
47
+ * useful.
48
+ */
49
+ convertEol?: boolean;
50
+
51
+ /**
52
+ * Whether the cursor blinks.
53
+ */
54
+ cursorBlink?: boolean;
55
+
56
+ /**
57
+ * The style of the cursor.
58
+ */
59
+ cursorStyle?: 'block' | 'underline' | 'bar';
60
+
61
+ /**
62
+ * The width of the cursor in CSS pixels when `cursorStyle` is set to 'bar'.
63
+ */
64
+ cursorWidth?: number;
65
+
66
+ /**
67
+ * Whether to draw custom glyphs for block element and box drawing
68
+ * characters instead of using the font. This should typically result in
69
+ * better rendering with continuous lines, even when line height and letter
70
+ * spacing is used. Note that this doesn't work with the DOM renderer which
71
+ * renders all characters using the font. The default is true.
72
+ */
73
+ customGlyphs?: boolean;
74
+ /**
75
+ * Whether input should be disabled.
76
+ */
77
+ disableStdin?: boolean;
78
+
79
+ /**
80
+ * Whether to draw bold text in bright colors. The default is true.
81
+ */
82
+ drawBoldTextInBrightColors?: boolean;
83
+
84
+ /**
85
+ * The modifier key hold to multiply scroll speed.
86
+ */
87
+ fastScrollModifier?: 'none' | 'alt' | 'ctrl' | 'shift';
88
+
89
+ /**
90
+ * The spacing in whole pixels between characters.
91
+ */
92
+ letterSpacing?: number;
93
+
94
+ /**
95
+ * The line height used to render text.
96
+ */
97
+ lineHeight?: number;
98
+
99
+ /**
100
+ * What log level to use, this will log for all levels below and including
101
+ * what is set:
102
+ *
103
+ * 1. trace
104
+ * 2. debug
105
+ * 3. info (default)
106
+ * 4. warn
107
+ * 5. error
108
+ * 6. off
109
+ */
110
+ logLevel?: LogLevel;
111
+
112
+ /**
113
+ * A logger to use instead of `console`.
114
+ */
115
+ logger?: ILogger | null;
116
+
117
+ /**
118
+ * Whether to treat option as the meta key.
119
+ */
120
+ macOptionIsMeta?: boolean;
121
+
122
+ /**
123
+ * Whether holding a modifier key will force normal selection behavior,
124
+ * regardless of whether the terminal is in mouse events mode. This will
125
+ * also prevent mouse events from being emitted by the terminal. For
126
+ * example, this allows you to use xterm.js' regular selection inside tmux
127
+ * with mouse mode enabled.
128
+ */
129
+ macOptionClickForcesSelection?: boolean;
130
+
131
+ /**
132
+ * The minimum contrast ratio for text in the terminal, setting this will
133
+ * change the foreground color dynamically depending on whether the contrast
134
+ * ratio is met. Example values:
135
+ *
136
+ * - 1: The default, do nothing.
137
+ * - 4.5: Minimum for WCAG AA compliance.
138
+ * - 7: Minimum for WCAG AAA compliance.
139
+ * - 21: White on black or black on white.
140
+ */
141
+ minimumContrastRatio?: number;
142
+
143
+ /**
144
+ * Whether to select the word under the cursor on right click, this is
145
+ * standard behavior in a lot of macOS applications.
146
+ */
147
+ rightClickSelectsWord?: boolean;
148
+
149
+ /**
150
+ * Whether screen reader support is enabled. When on this will expose
151
+ * supporting elements in the DOM to support NVDA on Windows and VoiceOver
152
+ * on macOS.
153
+ */
154
+ screenReaderMode?: boolean;
155
+
156
+ /**
157
+ * The amount of scrollback in the terminal. Scrollback is the amount of
158
+ * rows that are retained when lines are scrolled beyond the initial
159
+ * viewport.
160
+ */
161
+ scrollback?: number;
162
+
163
+ /**
164
+ * The scrolling speed multiplier used for adjusting normal scrolling speed.
165
+ */
166
+ scrollSensitivity?: number;
167
+
168
+ /**
169
+ * The duration to smoothly scroll between the origin and the target in
170
+ * milliseconds. Set to 0 to disable smooth scrolling and scroll instantly.
171
+ */
172
+ smoothScrollDuration?: number;
173
+
174
+ /**
175
+ * The size of tab stops in the terminal.
176
+ */
177
+ tabStopWidth?: number;
178
+
179
+ /**
180
+ * The color theme of the terminal.
181
+ */
182
+ theme?: ITheme;
183
+
184
+ /**
185
+ * Whether "Windows mode" is enabled. Because Windows backends winpty and
186
+ * conpty operate by doing line wrapping on their side, xterm.js does not
187
+ * have access to wrapped lines. When Windows mode is enabled the following
188
+ * changes will be in effect:
189
+ *
190
+ * - Reflow is disabled.
191
+ * - Lines are assumed to be wrapped if the last character of the line is
192
+ * not whitespace.
193
+ *
194
+ * When using conpty on Windows 11 version >= 21376, it is recommended to
195
+ * disable this because native text wrapping sequences are output correctly
196
+ * thanks to https://github.com/microsoft/terminal/issues/405
197
+ *
198
+ * @deprecated Use {@link windowsPty}. This value will be ignored if
199
+ * windowsPty is set.
200
+ */
201
+ windowsMode?: boolean;
202
+
203
+ /**
204
+ * Compatibility information when the pty is known to be hosted on Windows.
205
+ * Setting this will turn on certain heuristics/workarounds depending on the
206
+ * values:
207
+ *
208
+ * - `if (!!windowsCompat)`
209
+ * - When increasing the rows in the terminal, the amount increased into
210
+ * the scrollback. This is done because ConPTY does not behave like
211
+ * expect scrollback to come back into the viewport, instead it makes
212
+ * empty rows at of the viewport. Not having this behavior can result in
213
+ * missing data as the rows get replaced.
214
+ * - `if !(backend === 'conpty' && buildNumber >= 21376)`
215
+ * - Reflow is disabled
216
+ * - Lines are assumed to be wrapped if the last character of the line is
217
+ * not whitespace.
218
+ */
219
+ windowsPty?: IWindowsPty;
220
+
221
+ /**
222
+ * A string containing all characters that are considered word separated by
223
+ * the double click to select work logic.
224
+ */
225
+ wordSeparator?: string;
226
+
227
+ /**
228
+ * Enable various window manipulation and report features.
229
+ * All features are disabled by default for security reasons.
230
+ */
231
+ windowOptions?: IWindowOptions;
232
+ }
233
+
234
+ /**
235
+ * An object containing additional options for the terminal that can only be
236
+ * set on start up.
237
+ */
238
+ export interface ITerminalInitOnlyOptions {
239
+ /**
240
+ * The number of columns in the terminal.
241
+ */
242
+ cols?: number;
243
+
244
+ /**
245
+ * The number of rows in the terminal.
246
+ */
247
+ rows?: number;
248
+ }
249
+
250
+ /**
251
+ * Contains colors to theme the terminal with.
252
+ */
253
+ export interface ITheme {
254
+ /** The default foreground color */
255
+ foreground?: string;
256
+ /** The default background color */
257
+ background?: string;
258
+ /** The cursor color */
259
+ cursor?: string;
260
+ /** The accent color of the cursor (fg color for a block cursor) */
261
+ cursorAccent?: string;
262
+ /** The selection background color (can be transparent) */
263
+ selection?: string;
264
+ /** ANSI black (eg. `\x1b[30m`) */
265
+ black?: string;
266
+ /** ANSI red (eg. `\x1b[31m`) */
267
+ red?: string;
268
+ /** ANSI green (eg. `\x1b[32m`) */
269
+ green?: string;
270
+ /** ANSI yellow (eg. `\x1b[33m`) */
271
+ yellow?: string;
272
+ /** ANSI blue (eg. `\x1b[34m`) */
273
+ blue?: string;
274
+ /** ANSI magenta (eg. `\x1b[35m`) */
275
+ magenta?: string;
276
+ /** ANSI cyan (eg. `\x1b[36m`) */
277
+ cyan?: string;
278
+ /** ANSI white (eg. `\x1b[37m`) */
279
+ white?: string;
280
+ /** ANSI bright black (eg. `\x1b[1;30m`) */
281
+ brightBlack?: string;
282
+ /** ANSI bright red (eg. `\x1b[1;31m`) */
283
+ brightRed?: string;
284
+ /** ANSI bright green (eg. `\x1b[1;32m`) */
285
+ brightGreen?: string;
286
+ /** ANSI bright yellow (eg. `\x1b[1;33m`) */
287
+ brightYellow?: string;
288
+ /** ANSI bright blue (eg. `\x1b[1;34m`) */
289
+ brightBlue?: string;
290
+ /** ANSI bright magenta (eg. `\x1b[1;35m`) */
291
+ brightMagenta?: string;
292
+ /** ANSI bright cyan (eg. `\x1b[1;36m`) */
293
+ brightCyan?: string;
294
+ /** ANSI bright white (eg. `\x1b[1;37m`) */
295
+ brightWhite?: string;
296
+ /** ANSI extended colors (16-255) */
297
+ extendedAnsi?: string[];
298
+ }
299
+
300
+ /**
301
+ * Pty information for Windows.
302
+ */
303
+ export interface IWindowsPty {
304
+ /**
305
+ * What pty emulation backend is being used.
306
+ */
307
+ backend?: 'conpty' | 'winpty';
308
+ /**
309
+ * The Windows build version (eg. 19045)
310
+ */
311
+ buildNumber?: number;
312
+ }
313
+
314
+ /**
315
+ * A replacement logger for `console`.
316
+ */
317
+ export interface ILogger {
318
+ /**
319
+ * Log a trace message, this will only be called if
320
+ * {@link ITerminalOptions.logLevel} is set to trace.
321
+ */
322
+ trace(message: string, ...args: any[]): void;
323
+ /**
324
+ * Log a debug message, this will only be called if
325
+ * {@link ITerminalOptions.logLevel} is set to debug or below.
326
+ */
327
+ debug(message: string, ...args: any[]): void;
328
+ /**
329
+ * Log a debug message, this will only be called if
330
+ * {@link ITerminalOptions.logLevel} is set to info or below.
331
+ */
332
+ info(message: string, ...args: any[]): void;
333
+ /**
334
+ * Log a debug message, this will only be called if
335
+ * {@link ITerminalOptions.logLevel} is set to warn or below.
336
+ */
337
+ warn(message: string, ...args: any[]): void;
338
+ /**
339
+ * Log a debug message, this will only be called if
340
+ * {@link ITerminalOptions.logLevel} is set to error or below.
341
+ */
342
+ error(message: string | Error, ...args: any[]): void;
343
+ }
344
+
345
+ /**
346
+ * An object that can be disposed via a dispose function.
347
+ */
348
+ export interface IDisposable {
349
+ dispose(): void;
350
+ }
351
+
352
+ /**
353
+ * An event that can be listened to.
354
+ * @returns an `IDisposable` to stop listening.
355
+ */
356
+ export interface IEvent<T, U = void> {
357
+ (listener: (arg1: T, arg2: U) => any): IDisposable;
358
+ }
359
+
360
+ /**
361
+ * Represents a specific line in the terminal that is tracked when scrollback
362
+ * is trimmed and lines are added or removed. This is a single line that may
363
+ * be part of a larger wrapped line.
364
+ */
365
+ export interface IMarker extends IDisposableWithEvent {
366
+ /**
367
+ * A unique identifier for this marker.
368
+ */
369
+ readonly id: number;
370
+
371
+ /**
372
+ * The actual line index in the buffer at this point in time. This is set to
373
+ * -1 if the marker has been disposed.
374
+ */
375
+ readonly line: number;
376
+ }
377
+
378
+ /**
379
+ * Represents a disposable that tracks is disposed state.
380
+ */
381
+ export interface IDisposableWithEvent extends IDisposable {
382
+ /**
383
+ * Event listener to get notified when this gets disposed.
384
+ */
385
+ onDispose: IEvent<void>;
386
+
387
+ /**
388
+ * Whether this is disposed.
389
+ */
390
+ readonly isDisposed: boolean;
391
+ }
392
+
393
+ /**
394
+ * The set of localizable strings.
395
+ */
396
+ export interface ILocalizableStrings {
397
+ /**
398
+ * The aria label for the underlying input textarea for the terminal.
399
+ */
400
+ promptLabel: string;
401
+
402
+ /**
403
+ * Announcement for when line reading is suppressed due to too many lines
404
+ * being printed to the terminal when `screenReaderMode` is enabled.
405
+ */
406
+ tooMuchOutput: string;
407
+ }
408
+
409
+ /**
410
+ * Enable various window manipulation and report features
411
+ * (`CSI Ps ; Ps ; Ps t`).
412
+ *
413
+ * Most settings have no default implementation, as they heavily rely on
414
+ * the embedding environment.
415
+ *
416
+ * To implement a feature, create a custom CSI hook like this:
417
+ * ```ts
418
+ * term.parser.addCsiHandler({final: 't'}, params => {
419
+ * const ps = params[0];
420
+ * switch (ps) {
421
+ * case XY:
422
+ * ... // your implementation for option XY
423
+ * return true; // signal Ps=XY was handled
424
+ * }
425
+ * return false; // any Ps that was not handled
426
+ * });
427
+ * ```
428
+ *
429
+ * Note on security:
430
+ * Most features are meant to deal with some information of the host machine
431
+ * where the terminal runs on. This is seen as a security risk possibly
432
+ * leaking sensitive data of the host to the program in the terminal.
433
+ * Therefore all options (even those without a default implementation) are
434
+ * guarded by the boolean flag and disabled by default.
435
+ */
436
+ export interface IWindowOptions {
437
+ /**
438
+ * Ps=1 De-iconify window.
439
+ * No default implementation.
440
+ */
441
+ restoreWin?: boolean;
442
+ /**
443
+ * Ps=2 Iconify window.
444
+ * No default implementation.
445
+ */
446
+ minimizeWin?: boolean;
447
+ /**
448
+ * Ps=3 ; x ; y
449
+ * Move window to [x, y].
450
+ * No default implementation.
451
+ */
452
+ setWinPosition?: boolean;
453
+ /**
454
+ * Ps = 4 ; height ; width
455
+ * Resize the window to given `height` and `width` in pixels.
456
+ * Omitted parameters should reuse the current height or width.
457
+ * Zero parameters should use the display's height or width.
458
+ * No default implementation.
459
+ */
460
+ setWinSizePixels?: boolean;
461
+ /**
462
+ * Ps=5 Raise the window to the front of the stacking order.
463
+ * No default implementation.
464
+ */
465
+ raiseWin?: boolean;
466
+ /**
467
+ * Ps=6 Lower the xterm window to the bottom of the stacking order.
468
+ * No default implementation.
469
+ */
470
+ lowerWin?: boolean;
471
+ /** Ps=7 Refresh the window. */
472
+ refreshWin?: boolean;
473
+ /**
474
+ * Ps = 8 ; height ; width
475
+ * Resize the text area to given height and width in characters.
476
+ * Omitted parameters should reuse the current height or width.
477
+ * Zero parameters use the display's height or width.
478
+ * No default implementation.
479
+ */
480
+ setWinSizeChars?: boolean;
481
+ /**
482
+ * Ps=9 ; 0 Restore maximized window.
483
+ * Ps=9 ; 1 Maximize window (i.e., resize to screen size).
484
+ * Ps=9 ; 2 Maximize window vertically.
485
+ * Ps=9 ; 3 Maximize window horizontally.
486
+ * No default implementation.
487
+ */
488
+ maximizeWin?: boolean;
489
+ /**
490
+ * Ps=10 ; 0 Undo full-screen mode.
491
+ * Ps=10 ; 1 Change to full-screen.
492
+ * Ps=10 ; 2 Toggle full-screen.
493
+ * No default implementation.
494
+ */
495
+ fullscreenWin?: boolean;
496
+ /** Ps=11 Report xterm window state.
497
+ * If the xterm window is non-iconified, it returns "CSI 1 t".
498
+ * If the xterm window is iconified, it returns "CSI 2 t".
499
+ * No default implementation.
500
+ */
501
+ getWinState?: boolean;
502
+ /**
503
+ * Ps=13 Report xterm window position. Result is "CSI 3 ; x ; y t".
504
+ * Ps=13 ; 2 Report xterm text-area position. Result is "CSI 3 ; x ; y t".
505
+ * No default implementation.
506
+ */
507
+ getWinPosition?: boolean;
508
+ /**
509
+ * Ps=14 Report xterm text area size in pixels. Result is "CSI 4 ; height ; width t".
510
+ * Ps=14 ; 2 Report xterm window size in pixels. Result is "CSI 4 ; height ; width t".
511
+ * Has a default implementation.
512
+ */
513
+ getWinSizePixels?: boolean;
514
+ /**
515
+ * Ps=15 Report size of the screen in pixels. Result is "CSI 5 ; height ; width t".
516
+ * No default implementation.
517
+ */
518
+ getScreenSizePixels?: boolean;
519
+ /**
520
+ * Ps=16 Report xterm character cell size in pixels. Result is "CSI 6 ; height ; width t".
521
+ * Has a default implementation.
522
+ */
523
+ getCellSizePixels?: boolean;
524
+ /**
525
+ * Ps=18 Report the size of the text area in characters. Result is "CSI 8 ; height ; width t".
526
+ * Has a default implementation.
527
+ */
528
+ getWinSizeChars?: boolean;
529
+ /**
530
+ * Ps=19 Report the size of the screen in characters. Result is "CSI 9 ; height ; width t".
531
+ * No default implementation.
532
+ */
533
+ getScreenSizeChars?: boolean;
534
+ /**
535
+ * Ps=20 Report xterm window's icon label. Result is "OSC L label ST".
536
+ * No default implementation.
537
+ */
538
+ getIconTitle?: boolean;
539
+ /**
540
+ * Ps=21 Report xterm window's title. Result is "OSC l label ST".
541
+ * No default implementation.
542
+ */
543
+ getWinTitle?: boolean;
544
+ /**
545
+ * Ps=22 ; 0 Save xterm icon and window title on stack.
546
+ * Ps=22 ; 1 Save xterm icon title on stack.
547
+ * Ps=22 ; 2 Save xterm window title on stack.
548
+ * All variants have a default implementation.
549
+ */
550
+ pushTitle?: boolean;
551
+ /**
552
+ * Ps=23 ; 0 Restore xterm icon and window title from stack.
553
+ * Ps=23 ; 1 Restore xterm icon title from stack.
554
+ * Ps=23 ; 2 Restore xterm window title from stack.
555
+ * All variants have a default implementation.
556
+ */
557
+ popTitle?: boolean;
558
+ /**
559
+ * Ps>=24 Resize to Ps lines (DECSLPP).
560
+ * DECSLPP is not implemented. This settings is also used to
561
+ * enable / disable DECCOLM (earlier variant of DECSLPP).
562
+ */
563
+ setWinLines?: boolean;
564
+ }
565
+
566
+ /**
567
+ * The class that represents an xterm.js terminal.
568
+ */
569
+ export class Terminal implements IDisposable {
570
+ /**
571
+ * The number of rows in the terminal's viewport. Use
572
+ * `ITerminalOptions.rows` to set this in the constructor and
573
+ * `Terminal.resize` for when the terminal exists.
574
+ */
575
+ readonly rows: number;
576
+
577
+ /**
578
+ * The number of columns in the terminal's viewport. Use
579
+ * `ITerminalOptions.cols` to set this in the constructor and
580
+ * `Terminal.resize` for when the terminal exists.
581
+ */
582
+ readonly cols: number;
583
+
584
+ /**
585
+ * (EXPERIMENTAL) The terminal's current buffer, this might be either the
586
+ * normal buffer or the alt buffer depending on what's running in the
587
+ * terminal.
588
+ */
589
+ readonly buffer: IBufferNamespace;
590
+
591
+ /**
592
+ * (EXPERIMENTAL) Get all markers registered against the buffer. If the alt
593
+ * buffer is active this will always return [].
594
+ */
595
+ readonly markers: ReadonlyArray<IMarker>;
596
+
597
+ /**
598
+ * (EXPERIMENTAL) Get the parser interface to register
599
+ * custom escape sequence handlers.
600
+ */
601
+ readonly parser: IParser;
602
+
603
+ /**
604
+ * (EXPERIMENTAL) Get the Unicode handling interface
605
+ * to register and switch Unicode version.
606
+ */
607
+ readonly unicode: IUnicodeHandling;
608
+
609
+ /**
610
+ * Gets the terminal modes as set by SM/DECSET.
611
+ */
612
+ readonly modes: IModes;
613
+
614
+ /**
615
+ * Gets or sets the terminal options. This supports setting multiple
616
+ * options.
617
+ *
618
+ * @example Get a single option
619
+ * ```ts
620
+ * console.log(terminal.options.fontSize);
621
+ * ```
622
+ *
623
+ * @example Set a single option:
624
+ * ```ts
625
+ * terminal.options.fontSize = 12;
626
+ * ```
627
+ * Note that for options that are object, a new object must be used in order
628
+ * to take effect as a reference comparison will be done:
629
+ * ```ts
630
+ * const newValue = terminal.options.theme;
631
+ * newValue.background = '#000000';
632
+ *
633
+ * // This won't work
634
+ * terminal.options.theme = newValue;
635
+ *
636
+ * // This will work
637
+ * terminal.options.theme = { ...newValue };
638
+ * ```
639
+ *
640
+ * @example Set multiple options
641
+ * ```ts
642
+ * terminal.options = {
643
+ * fontSize: 12,
644
+ * fontFamily: 'Courier New'
645
+ * };
646
+ * ```
647
+ */
648
+ options: ITerminalOptions;
649
+
650
+ /**
651
+ * Natural language strings that can be localized.
652
+ */
653
+ static strings: ILocalizableStrings;
654
+
655
+ /**
656
+ * Creates a new `Terminal` object.
657
+ *
658
+ * @param options An object containing a set of options.
659
+ */
660
+ constructor(options?: ITerminalOptions & ITerminalInitOnlyOptions);
661
+
662
+ /**
663
+ * Adds an event listener for when the bell is triggered.
664
+ * @returns an `IDisposable` to stop listening.
665
+ */
666
+ onBell: IEvent<void>;
667
+
668
+ /**
669
+ * Adds an event listener for when a binary event fires. This is used to
670
+ * enable non UTF-8 conformant binary messages to be sent to the backend.
671
+ * Currently this is only used for a certain type of mouse reports that
672
+ * happen to be not UTF-8 compatible.
673
+ * The event value is a JS string, pass it to the underlying pty as
674
+ * binary data, e.g. `pty.write(Buffer.from(data, 'binary'))`.
675
+ * @returns an `IDisposable` to stop listening.
676
+ */
677
+ onBinary: IEvent<string>;
678
+
679
+ /**
680
+ * Adds an event listener for the cursor moves.
681
+ * @returns an `IDisposable` to stop listening.
682
+ */
683
+ onCursorMove: IEvent<void>;
684
+
685
+ /**
686
+ * Adds an event listener for when a data event fires. This happens for
687
+ * example when the user types or pastes into the terminal. The event value
688
+ * is whatever `string` results, in a typical setup, this should be passed
689
+ * on to the backing pty.
690
+ * @returns an `IDisposable` to stop listening.
691
+ */
692
+ onData: IEvent<string>;
693
+
694
+ /**
695
+ * Adds an event listener for when a line feed is added.
696
+ * @returns an `IDisposable` to stop listening.
697
+ */
698
+ onLineFeed: IEvent<void>;
699
+
700
+ /**
701
+ * Adds an event listener for when the terminal is resized. The event value
702
+ * contains the new size.
703
+ * @returns an `IDisposable` to stop listening.
704
+ */
705
+ onResize: IEvent<{ cols: number, rows: number }>;
706
+
707
+ /**
708
+ * Adds an event listener for when a scroll occurs. The event value is the
709
+ * new position of the viewport.
710
+ * @returns an `IDisposable` to stop listening.
711
+ */
712
+ onScroll: IEvent<number>;
713
+
714
+ /**
715
+ * Adds an event listener for when an OSC 0 or OSC 2 title change occurs.
716
+ * The event value is the new title.
717
+ * @returns an `IDisposable` to stop listening.
718
+ */
719
+ onTitleChange: IEvent<string>;
720
+
721
+ /**
722
+ * Resizes the terminal. It's best practice to debounce calls to resize,
723
+ * this will help ensure that the pty can respond to the resize event
724
+ * before another one occurs.
725
+ * @param x The number of columns to resize to.
726
+ * @param y The number of rows to resize to.
727
+ */
728
+ resize(columns: number, rows: number): void;
729
+
730
+ /**
731
+ * Adds a marker to the normal buffer and returns it. If the alt buffer is
732
+ * active, undefined is returned.
733
+ * @param cursorYOffset The y position offset of the marker from the cursor.
734
+ * @returns The new marker or undefined.
735
+ */
736
+ registerMarker(cursorYOffset?: number): IMarker | undefined;
737
+
738
+ /*
739
+ * Disposes of the terminal, detaching it from the DOM and removing any
740
+ * active listeners. Once the terminal is disposed it should not be used
741
+ * again.
742
+ */
743
+ dispose(): void;
744
+
745
+ /**
746
+ * Scroll the display of the terminal
747
+ * @param amount The number of lines to scroll down (negative scroll up).
748
+ */
749
+ scrollLines(amount: number): void;
750
+
751
+ /**
752
+ * Scroll the display of the terminal by a number of pages.
753
+ * @param pageCount The number of pages to scroll (negative scrolls up).
754
+ */
755
+ scrollPages(pageCount: number): void;
756
+
757
+ /**
758
+ * Scrolls the display of the terminal to the top.
759
+ */
760
+ scrollToTop(): void;
761
+
762
+ /**
763
+ * Scrolls the display of the terminal to the bottom.
764
+ */
765
+ scrollToBottom(): void;
766
+
767
+ /**
768
+ * Scrolls to a line within the buffer.
769
+ * @param line The 0-based line index to scroll to.
770
+ */
771
+ scrollToLine(line: number): void;
772
+
773
+ /**
774
+ * Clear the entire buffer, making the prompt line the new first line.
775
+ */
776
+ clear(): void;
777
+
778
+ /**
779
+ * Write data to the terminal.
780
+ * @param data The data to write to the terminal. This can either be raw
781
+ * bytes given as Uint8Array from the pty or a string. Raw bytes will always
782
+ * be treated as UTF-8 encoded, string data as UTF-16.
783
+ * @param callback Optional callback that fires when the data was processed
784
+ * by the parser.
785
+ */
786
+ write(data: string | Uint8Array, callback?: () => void): void;
787
+
788
+ /**
789
+ * Writes data to the terminal, followed by a break line character (\n).
790
+ * @param data The data to write to the terminal. This can either be raw
791
+ * bytes given as Uint8Array from the pty or a string. Raw bytes will always
792
+ * be treated as UTF-8 encoded, string data as UTF-16.
793
+ * @param callback Optional callback that fires when the data was processed
794
+ * by the parser.
795
+ */
796
+ writeln(data: string | Uint8Array, callback?: () => void): void;
797
+
798
+ /**
799
+ * Perform a full reset (RIS, aka '\x1bc').
800
+ */
801
+ reset(): void;
802
+
803
+ /**
804
+ * Loads an addon into this instance of xterm.js.
805
+ * @param addon The addon to load.
806
+ */
807
+ loadAddon(addon: ITerminalAddon): void;
808
+ }
809
+
810
+ /**
811
+ * An addon that can provide additional functionality to the terminal.
812
+ */
813
+ export interface ITerminalAddon extends IDisposable {
814
+ /**
815
+ * This is called when the addon is activated.
816
+ */
817
+ activate(terminal: Terminal): void;
818
+ }
819
+
820
+ /**
821
+ * An object representing a range within the viewport of the terminal.
822
+ */
823
+ export interface IViewportRange {
824
+ /**
825
+ * The start of the range.
826
+ */
827
+ start: IViewportRangePosition;
828
+
829
+ /**
830
+ * The end of the range.
831
+ */
832
+ end: IViewportRangePosition;
833
+ }
834
+
835
+ /**
836
+ * An object representing a cell position within the viewport of the terminal.
837
+ */
838
+ interface IViewportRangePosition {
839
+ /**
840
+ * The x position of the cell. This is a 0-based index that refers to the
841
+ * space in between columns, not the column itself. Index 0 refers to the
842
+ * left side of the viewport, index `Terminal.cols` refers to the right side
843
+ * of the viewport. This can be thought of as how a cursor is positioned in
844
+ * a text editor.
845
+ */
846
+ x: number;
847
+
848
+ /**
849
+ * The y position of the cell. This is a 0-based index that refers to a
850
+ * specific row.
851
+ */
852
+ y: number;
853
+ }
854
+
855
+ /**
856
+ * A range within a buffer.
857
+ */
858
+ interface IBufferRange {
859
+ /**
860
+ * The start position of the range.
861
+ */
862
+ start: IBufferCellPosition;
863
+
864
+ /**
865
+ * The end position of the range.
866
+ */
867
+ end: IBufferCellPosition;
868
+ }
869
+
870
+ /**
871
+ * A position within a buffer.
872
+ */
873
+ interface IBufferCellPosition {
874
+ /**
875
+ * The x position within the buffer.
876
+ */
877
+ x: number;
878
+
879
+ /**
880
+ * The y position within the buffer.
881
+ */
882
+ y: number;
883
+ }
884
+
885
+ /**
886
+ * Represents a terminal buffer.
887
+ */
888
+ interface IBuffer {
889
+ /**
890
+ * The type of the buffer.
891
+ */
892
+ readonly type: 'normal' | 'alternate';
893
+
894
+ /**
895
+ * The y position of the cursor. This ranges between `0` (when the
896
+ * cursor is at baseY) and `Terminal.rows - 1` (when the cursor is on the
897
+ * last row).
898
+ */
899
+ readonly cursorY: number;
900
+
901
+ /**
902
+ * The x position of the cursor. This ranges between `0` (left side) and
903
+ * `Terminal.cols` (after last cell of the row).
904
+ */
905
+ readonly cursorX: number;
906
+
907
+ /**
908
+ * The line within the buffer where the top of the viewport is.
909
+ */
910
+ readonly viewportY: number;
911
+
912
+ /**
913
+ * The line within the buffer where the top of the bottom page is (when
914
+ * fully scrolled down).
915
+ */
916
+ readonly baseY: number;
917
+
918
+ /**
919
+ * The amount of lines in the buffer.
920
+ */
921
+ readonly length: number;
922
+
923
+ /**
924
+ * Gets a line from the buffer, or undefined if the line index does not
925
+ * exist.
926
+ *
927
+ * Note that the result of this function should be used immediately after
928
+ * calling as when the terminal updates it could lead to unexpected
929
+ * behavior.
930
+ *
931
+ * @param y The line index to get.
932
+ */
933
+ getLine(y: number): IBufferLine | undefined;
934
+
935
+ /**
936
+ * Creates an empty cell object suitable as a cell reference in
937
+ * `line.getCell(x, cell)`. Use this to avoid costly recreation of
938
+ * cell objects when dealing with tons of cells.
939
+ */
940
+ getNullCell(): IBufferCell;
941
+ }
942
+
943
+ /**
944
+ * Represents the terminal's set of buffers.
945
+ */
946
+ interface IBufferNamespace {
947
+ /**
948
+ * The active buffer, this will either be the normal or alternate buffers.
949
+ */
950
+ readonly active: IBuffer;
951
+
952
+ /**
953
+ * The normal buffer.
954
+ */
955
+ readonly normal: IBuffer;
956
+
957
+ /**
958
+ * The alternate buffer, this becomes the active buffer when an application
959
+ * enters this mode via DECSET (`CSI ? 4 7 h`)
960
+ */
961
+ readonly alternate: IBuffer;
962
+
963
+ /**
964
+ * Adds an event listener for when the active buffer changes.
965
+ * @returns an `IDisposable` to stop listening.
966
+ */
967
+ onBufferChange: IEvent<IBuffer>;
968
+ }
969
+
970
+ /**
971
+ * Represents a line in the terminal's buffer.
972
+ */
973
+ interface IBufferLine {
974
+ /**
975
+ * Whether the line is wrapped from the previous line.
976
+ */
977
+ readonly isWrapped: boolean;
978
+
979
+ /**
980
+ * The length of the line, all call to getCell beyond the length will result
981
+ * in `undefined`.
982
+ */
983
+ readonly length: number;
984
+
985
+ /**
986
+ * Gets a cell from the line, or undefined if the line index does not exist.
987
+ *
988
+ * Note that the result of this function should be used immediately after
989
+ * calling as when the terminal updates it could lead to unexpected
990
+ * behavior.
991
+ *
992
+ * @param x The character index to get.
993
+ * @param cell Optional cell object to load data into for performance
994
+ * reasons. This is mainly useful when every cell in the buffer is being
995
+ * looped over to avoid creating new objects for every cell.
996
+ */
997
+ getCell(x: number, cell?: IBufferCell): IBufferCell | undefined;
998
+
999
+ /**
1000
+ * Gets the line as a string. Note that this is gets only the string for the
1001
+ * line, not taking isWrapped into account.
1002
+ *
1003
+ * @param trimRight Whether to trim any whitespace at the right of the line.
1004
+ * @param startColumn The column to start from (inclusive).
1005
+ * @param endColumn The column to end at (exclusive).
1006
+ */
1007
+ translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
1008
+ }
1009
+
1010
+ /**
1011
+ * Represents a single cell in the terminal's buffer.
1012
+ */
1013
+ interface IBufferCell {
1014
+ /**
1015
+ * The width of the character. Some examples:
1016
+ *
1017
+ * - `1` for most cells.
1018
+ * - `2` for wide character like CJK glyphs.
1019
+ * - `0` for cells immediately following cells with a width of `2`.
1020
+ */
1021
+ getWidth(): number;
1022
+
1023
+ /**
1024
+ * The character(s) within the cell. Examples of what this can contain:
1025
+ *
1026
+ * - A normal width character
1027
+ * - A wide character (eg. CJK)
1028
+ * - An emoji
1029
+ */
1030
+ getChars(): string;
1031
+
1032
+ /**
1033
+ * Gets the UTF32 codepoint of single characters, if content is a combined
1034
+ * string it returns the codepoint of the last character in the string.
1035
+ */
1036
+ getCode(): number;
1037
+
1038
+ /**
1039
+ * Gets the number representation of the foreground color mode, this can be
1040
+ * used to perform quick comparisons of 2 cells to see if they're the same.
1041
+ * Use `isFgRGB`, `isFgPalette` and `isFgDefault` to check what color mode
1042
+ * a cell is.
1043
+ */
1044
+ getFgColorMode(): number;
1045
+
1046
+ /**
1047
+ * Gets the number representation of the background color mode, this can be
1048
+ * used to perform quick comparisons of 2 cells to see if they're the same.
1049
+ * Use `isBgRGB`, `isBgPalette` and `isBgDefault` to check what color mode
1050
+ * a cell is.
1051
+ */
1052
+ getBgColorMode(): number;
1053
+
1054
+ /**
1055
+ * Gets a cell's foreground color number, this differs depending on what the
1056
+ * color mode of the cell is:
1057
+ *
1058
+ * - Default: This should be 0, representing the default foreground color
1059
+ * (CSI 39 m).
1060
+ * - Palette: This is a number from 0 to 255 of ANSI colors (CSI 3(0-7) m,
1061
+ * CSI 9(0-7) m, CSI 38 ; 5 ; 0-255 m).
1062
+ * - RGB: A hex value representing a 'true color': 0xRRGGBB.
1063
+ * (CSI 3 8 ; 2 ; Pi ; Pr ; Pg ; Pb)
1064
+ */
1065
+ getFgColor(): number;
1066
+
1067
+ /**
1068
+ * Gets a cell's background color number, this differs depending on what the
1069
+ * color mode of the cell is:
1070
+ *
1071
+ * - Default: This should be 0, representing the default background color
1072
+ * (CSI 49 m).
1073
+ * - Palette: This is a number from 0 to 255 of ANSI colors
1074
+ * (CSI 4(0-7) m, CSI 10(0-7) m, CSI 48 ; 5 ; 0-255 m).
1075
+ * - RGB: A hex value representing a 'true color': 0xRRGGBB
1076
+ * (CSI 4 8 ; 2 ; Pi ; Pr ; Pg ; Pb)
1077
+ */
1078
+ getBgColor(): number;
1079
+
1080
+ /** Whether the cell has the bold attribute (CSI 1 m). */
1081
+ isBold(): number;
1082
+ /** Whether the cell has the italic attribute (CSI 3 m). */
1083
+ isItalic(): number;
1084
+ /** Whether the cell has the dim attribute (CSI 2 m). */
1085
+ isDim(): number;
1086
+ /** Whether the cell has the underline attribute (CSI 4 m). */
1087
+ isUnderline(): number;
1088
+ /** Whether the cell has the blink attribute (CSI 5 m). */
1089
+ isBlink(): number;
1090
+ /** Whether the cell has the inverse attribute (CSI 7 m). */
1091
+ isInverse(): number;
1092
+ /** Whether the cell has the invisible attribute (CSI 8 m). */
1093
+ isInvisible(): number;
1094
+ /** Whether the cell has the strikethrough attribute (CSI 9 m). */
1095
+ isStrikethrough(): number;
1096
+ /** Whether the cell has the overline attribute (CSI 53 m). */
1097
+ isOverline(): number;
1098
+
1099
+ /** Whether the cell is using the RGB foreground color mode. */
1100
+ isFgRGB(): boolean;
1101
+ /** Whether the cell is using the RGB background color mode. */
1102
+ isBgRGB(): boolean;
1103
+ /** Whether the cell is using the palette foreground color mode. */
1104
+ isFgPalette(): boolean;
1105
+ /** Whether the cell is using the palette background color mode. */
1106
+ isBgPalette(): boolean;
1107
+ /** Whether the cell is using the default foreground color mode. */
1108
+ isFgDefault(): boolean;
1109
+ /** Whether the cell is using the default background color mode. */
1110
+ isBgDefault(): boolean;
1111
+
1112
+ /** Whether the cell has the default attribute (no color or style). */
1113
+ isAttributeDefault(): boolean;
1114
+ }
1115
+
1116
+ /**
1117
+ * Data type to register a CSI, DCS or ESC callback in the parser
1118
+ * in the form:
1119
+ * ESC I..I F
1120
+ * CSI Prefix P..P I..I F
1121
+ * DCS Prefix P..P I..I F data_bytes ST
1122
+ *
1123
+ * with these rules/restrictions:
1124
+ * - prefix can only be used with CSI and DCS
1125
+ * - only one leading prefix byte is recognized by the parser
1126
+ * before any other parameter bytes (P..P)
1127
+ * - intermediate bytes are recognized up to 2
1128
+ *
1129
+ * For custom sequences make sure to read ECMA-48 and the resources at
1130
+ * vt100.net to not clash with existing sequences or reserved address space.
1131
+ * General recommendations:
1132
+ * - use private address space (see ECMA-48)
1133
+ * - use max one intermediate byte (technically not limited by the spec,
1134
+ * in practice there are no sequences with more than one intermediate byte,
1135
+ * thus parsers might get confused with more intermediates)
1136
+ * - test against other common emulators to check whether they escape/ignore
1137
+ * the sequence correctly
1138
+ *
1139
+ * Notes: OSC command registration is handled differently (see addOscHandler)
1140
+ * APC, PM or SOS is currently not supported.
1141
+ */
1142
+ export interface IFunctionIdentifier {
1143
+ /**
1144
+ * Optional prefix byte, must be in range \x3c .. \x3f.
1145
+ * Usable in CSI and DCS.
1146
+ */
1147
+ prefix?: string;
1148
+ /**
1149
+ * Optional intermediate bytes, must be in range \x20 .. \x2f.
1150
+ * Usable in CSI, DCS and ESC.
1151
+ */
1152
+ intermediates?: string;
1153
+ /**
1154
+ * Final byte, must be in range \x40 .. \x7e for CSI and DCS,
1155
+ * \x30 .. \x7e for ESC.
1156
+ */
1157
+ final: string;
1158
+ }
1159
+
1160
+ /**
1161
+ * Allows hooking into the parser for custom handling of escape sequences.
1162
+ */
1163
+ export interface IParser {
1164
+ /**
1165
+ * Adds a handler for CSI escape sequences.
1166
+ * @param id Specifies the function identifier under which the callback
1167
+ * gets registered, e.g. {final: 'm'} for SGR.
1168
+ * @param callback The function to handle the sequence. The callback is
1169
+ * called with the numerical params. If the sequence has subparams the
1170
+ * array will contain subarrays with their numercial values.
1171
+ * Return true if the sequence was handled; false if we should try
1172
+ * a previous handler (set by addCsiHandler or setCsiHandler).
1173
+ * The most recently added handler is tried first.
1174
+ * @returns An IDisposable you can call to remove this handler.
1175
+ */
1176
+ registerCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean): IDisposable;
1177
+
1178
+ /**
1179
+ * Adds a handler for DCS escape sequences.
1180
+ * @param id Specifies the function identifier under which the callback
1181
+ * gets registered, e.g. {intermediates: '$' final: 'q'} for DECRQSS.
1182
+ * @param callback The function to handle the sequence. Note that the
1183
+ * function will only be called once if the sequence finished sucessfully.
1184
+ * There is currently no way to intercept smaller data chunks, data chunks
1185
+ * will be stored up until the sequence is finished. Since DCS sequences
1186
+ * are not limited by the amount of data this might impose a problem for
1187
+ * big payloads. Currently xterm.js limits DCS payload to 10 MB
1188
+ * which should give enough room for most use cases.
1189
+ * The function gets the payload and numerical parameters as arguments.
1190
+ * Return true if the sequence was handled; false if we should try
1191
+ * a previous handler (set by addDcsHandler or setDcsHandler).
1192
+ * The most recently added handler is tried first.
1193
+ * @returns An IDisposable you can call to remove this handler.
1194
+ */
1195
+ registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean): IDisposable;
1196
+
1197
+ /**
1198
+ * Adds a handler for ESC escape sequences.
1199
+ * @param id Specifies the function identifier under which the callback
1200
+ * gets registered, e.g. {intermediates: '%' final: 'G'} for
1201
+ * default charset selection.
1202
+ * @param callback The function to handle the sequence.
1203
+ * Return true if the sequence was handled; false if we should try
1204
+ * a previous handler (set by addEscHandler or setEscHandler).
1205
+ * The most recently added handler is tried first.
1206
+ * @returns An IDisposable you can call to remove this handler.
1207
+ */
1208
+ registerEscHandler(id: IFunctionIdentifier, handler: () => boolean): IDisposable;
1209
+
1210
+ /**
1211
+ * Adds a handler for OSC escape sequences.
1212
+ * @param ident The number (first parameter) of the sequence.
1213
+ * @param callback The function to handle the sequence. Note that the
1214
+ * function will only be called once if the sequence finished sucessfully.
1215
+ * There is currently no way to intercept smaller data chunks, data chunks
1216
+ * will be stored up until the sequence is finished. Since OSC sequences
1217
+ * are not limited by the amount of data this might impose a problem for
1218
+ * big payloads. Currently xterm.js limits OSC payload to 10 MB
1219
+ * which should give enough room for most use cases.
1220
+ * The callback is called with OSC data string.
1221
+ * Return true if the sequence was handled; false if we should try
1222
+ * a previous handler (set by addOscHandler or setOscHandler).
1223
+ * The most recently added handler is tried first.
1224
+ * @returns An IDisposable you can call to remove this handler.
1225
+ */
1226
+ registerOscHandler(ident: number, callback: (data: string) => boolean): IDisposable;
1227
+ }
1228
+
1229
+ /**
1230
+ * (EXPERIMENTAL) Unicode version provider.
1231
+ * Used to register custom Unicode versions with `Terminal.unicode.register`.
1232
+ */
1233
+ export interface IUnicodeVersionProvider {
1234
+ /**
1235
+ * String indicating the Unicode version provided.
1236
+ */
1237
+ readonly version: string;
1238
+
1239
+ /**
1240
+ * Unicode version dependent wcwidth implementation.
1241
+ */
1242
+ wcwidth(codepoint: number): 0 | 1 | 2;
1243
+ charProperties(codepoint: number, preceding: number): number;
1244
+ }
1245
+
1246
+ /**
1247
+ * (EXPERIMENTAL) Unicode handling interface.
1248
+ */
1249
+ export interface IUnicodeHandling {
1250
+ /**
1251
+ * Register a custom Unicode version provider.
1252
+ */
1253
+ register(provider: IUnicodeVersionProvider): void;
1254
+
1255
+ /**
1256
+ * Registered Unicode versions.
1257
+ */
1258
+ readonly versions: ReadonlyArray<string>;
1259
+
1260
+ /**
1261
+ * Getter/setter for active Unicode version.
1262
+ */
1263
+ activeVersion: string;
1264
+ }
1265
+
1266
+ /**
1267
+ * Terminal modes as set by SM/DECSET.
1268
+ */
1269
+ export interface IModes {
1270
+ /**
1271
+ * Application Cursor Keys (DECCKM): `CSI ? 1 h`
1272
+ */
1273
+ readonly applicationCursorKeysMode: boolean;
1274
+ /**
1275
+ * Application Keypad Mode (DECNKM): `CSI ? 6 6 h`
1276
+ */
1277
+ readonly applicationKeypadMode: boolean;
1278
+ /**
1279
+ * Bracketed Paste Mode: `CSI ? 2 0 0 4 h`
1280
+ */
1281
+ readonly bracketedPasteMode: boolean;
1282
+ /**
1283
+ * Insert Mode (IRM): `CSI 4 h`
1284
+ */
1285
+ readonly insertMode: boolean;
1286
+ /**
1287
+ * Mouse Tracking, this can be one of the following:
1288
+ * - none: This is the default value and can be reset with DECRST
1289
+ * - x10: Send Mouse X & Y on button press `CSI ? 9 h`
1290
+ * - vt200: Send Mouse X & Y on button press and release `CSI ? 1 0 0 0 h`
1291
+ * - drag: Use Cell Motion Mouse Tracking `CSI ? 1 0 0 2 h`
1292
+ * - any: Use All Motion Mouse Tracking `CSI ? 1 0 0 3 h`
1293
+ */
1294
+ readonly mouseTrackingMode: 'none' | 'x10' | 'vt200' | 'drag' | 'any';
1295
+ /**
1296
+ * Origin Mode (DECOM): `CSI ? 6 h`
1297
+ */
1298
+ readonly originMode: boolean;
1299
+ /**
1300
+ * Reverse-wraparound Mode: `CSI ? 4 5 h`
1301
+ */
1302
+ readonly reverseWraparoundMode: boolean;
1303
+ /**
1304
+ * Send FocusIn/FocusOut events: `CSI ? 1 0 0 4 h`
1305
+ */
1306
+ readonly sendFocusMode: boolean;
1307
+ /**
1308
+ * Auto-Wrap Mode (DECAWM): `CSI ? 7 h`
1309
+ */
1310
+ readonly wraparoundMode: boolean;
1311
+ }
1312
+ }