Debian Codegraph @

node/@xterm/xterm/typings/xterm.d.ts

raw
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 /// <reference lib="dom"/>
11
12 declare module '@xterm/xterm' {
13 /**
14 * A string or number representing text font weight.
15 */
16 export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number;
17
18 /**
19 * A string representing log level.
20 */
21 export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off';
22
23 /**
24 * An object containing options for the terminal.
25 */
26 export interface ITerminalOptions {
27 /**
28 * Whether to allow the use of proposed API. When false, any usage of APIs
29 * marked as experimental/proposed will throw an error. The default is
30 * false.
31 */
32 allowProposedApi?: boolean;
33
34 /**
35 * Whether background should support non-opaque color. It must be set before
36 * executing the `Terminal.open()` method and can't be changed later without
37 * executing it again. Note that enabling this can negatively impact
38 * performance.
39 */
40 allowTransparency?: boolean;
41
42 /**
43 * If enabled, alt + click will move the prompt cursor to position
44 * underneath the mouse. The default is true.
45 */
46 altClickMovesCursor?: boolean;
47
48 /**
49 * When enabled the cursor will be set to the beginning of the next line
50 * with every new line. This is equivalent to sending `\r\n` for each `\n`.
51 * Normally the settings of the underlying PTY (`termios`) deal with the
52 * translation of `\n` to `\r\n` and this setting should not be used. If you
53 * deal with data from a non-PTY related source, this settings might be
54 * useful.
55 *
56 * @see https://pubs.opengroup.org/onlinepubs/007904975/basedefs/termios.h.html
57 */
58 convertEol?: boolean;
59
60 /**
61 * Whether the cursor blinks.
62 */
63 cursorBlink?: boolean;
64
65 /**
66 * The style of the cursor when the terminal is focused.
67 */
68 cursorStyle?: 'block' | 'underline' | 'bar';
69
70 /**
71 * The width of the cursor in CSS pixels when `cursorStyle` is set to 'bar'.
72 */
73 cursorWidth?: number;
74
75 /**
76 * The style of the cursor when the terminal is not focused.
77 */
78 cursorInactiveStyle?: 'outline' | 'block' | 'bar' | 'underline' | 'none';
79
80 /**
81 * Whether to draw custom glyphs for block element and box drawing
82 * characters instead of using the font. This should typically result in
83 * better rendering with continuous lines, even when line height and letter
84 * spacing is used. Note that this doesn't work with the DOM renderer which
85 * renders all characters using the font. The default is true.
86 */
87 customGlyphs?: boolean;
88
89 /**
90 * Whether input should be disabled.
91 */
92 disableStdin?: boolean;
93
94 /**
95 * A {@link Document} to use instead of the one that xterm.js was attached
96 * to. The purpose of this is to improve support in multi-window
97 * applications where HTML elements may be references across multiple
98 * windows which can cause problems with `instanceof`.
99 *
100 * The type is `any` because using `Document` can cause TS to have
101 * performance/compiler problems.
102 */
103 documentOverride?: any | null;
104
105 /**
106 * Whether to draw bold text in bright colors. The default is true.
107 */
108 drawBoldTextInBrightColors?: boolean;
109
110 /**
111 * The scroll speed multiplier used for fast scrolling when `Alt` is held.
112 */
113 fastScrollSensitivity?: number;
114
115 /**
116 * The font size used to render text.
117 */
118 fontSize?: number;
119
120 /**
121 * The font family used to render text.
122 */
123 fontFamily?: string;
124
125 /**
126 * The font weight used to render non-bold text.
127 */
128 fontWeight?: FontWeight;
129
130 /**
131 * The font weight used to render bold text.
132 */
133 fontWeightBold?: FontWeight;
134
135 /**
136 * Whether to ignore the bracketed paste mode. When true, this will always
137 * paste without the `\x1b[200~` and `\x1b[201~` sequences, even when the
138 * shell enables bracketed mode.
139 */
140 ignoreBracketedPasteMode?: boolean;
141
142 /**
143 * The spacing in whole pixels between characters.
144 */
145 letterSpacing?: number;
146
147 /**
148 * The line height used to render text.
149 */
150 lineHeight?: number;
151
152 /**
153 * The handler for OSC 8 hyperlinks. Links will use the `confirm` browser
154 * API with a strongly worded warning if no link handler is set.
155 *
156 * When setting this, consider the security of users opening these links,
157 * at a minimum there should be a tooltip or a prompt when hovering or
158 * activating the link respectively. An example of what might be possible is
159 * a terminal app writing link in the form `javascript:...` that runs some
160 * javascript, a safe approach to prevent that is to validate the link
161 * starts with http(s)://.
162 */
163 linkHandler?: ILinkHandler | null;
164
165 /**
166 * What log level to use, this will log for all levels below and including
167 * what is set:
168 *
169 * 1. trace
170 * 2. debug
171 * 3. info (default)
172 * 4. warn
173 * 5. error
174 * 6. off
175 */
176 logLevel?: LogLevel;
177
178 /**
179 * A logger to use instead of `console`.
180 */
181 logger?: ILogger | null;
182
183 /**
184 * Whether to treat option as the meta key.
185 */
186 macOptionIsMeta?: boolean;
187
188 /**
189 * Whether holding a modifier key will force normal selection behavior,
190 * regardless of whether the terminal is in mouse events mode. This will
191 * also prevent mouse events from being emitted by the terminal. For
192 * example, this allows you to use xterm.js' regular selection inside tmux
193 * with mouse mode enabled.
194 */
195 macOptionClickForcesSelection?: boolean;
196
197 /**
198 * The minimum contrast ratio for text in the terminal, setting this will
199 * change the foreground color dynamically depending on whether the contrast
200 * ratio is met. Example values:
201 *
202 * - 1: The default, do nothing.
203 * - 4.5: Minimum for WCAG AA compliance.
204 * - 7: Minimum for WCAG AAA compliance.
205 * - 21: White on black or black on white.
206 */
207 minimumContrastRatio?: number;
208
209 /**
210 * Whether to reflow the line containing the cursor when the terminal is
211 * resized. Defaults to false, because shells usually handle this
212 * themselves.
213 */
214 reflowCursorLine?: boolean;
215
216 /**
217 * Whether to rescale glyphs horizontally that are a single cell wide but
218 * have glyphs that would overlap following cell(s). This typically happens
219 * for ambiguous width characters (eg. the roman numeral characters U+2160+)
220 * which aren't featured in monospace fonts. This is an important feature
221 * for achieving GB18030 compliance.
222 *
223 * The following glyphs will never be rescaled:
224 *
225 * - Emoji glyphs
226 * - Powerline glyphs
227 * - Nerd font glyphs
228 *
229 * Note that this doesn't work with the DOM renderer. The default is false.
230 */
231 rescaleOverlappingGlyphs?: boolean;
232
233 /**
234 * Whether to select the word under the cursor on right click, this is
235 * standard behavior in a lot of macOS applications.
236 */
237 rightClickSelectsWord?: boolean;
238
239 /**
240 * Whether screen reader support is enabled. When on this will expose
241 * supporting elements in the DOM to support NVDA on Windows and VoiceOver
242 * on macOS.
243 */
244 screenReaderMode?: boolean;
245
246 /**
247 * The amount of scrollback in the terminal. Scrollback is the amount of
248 * rows that are retained when lines are scrolled beyond the initial
249 * viewport. Defaults to 1000.
250 */
251 scrollback?: number;
252
253 /**
254 * If enabled the Erase in Display All (ED2) escape sequence will push
255 * erased text to scrollback, instead of clearing only the viewport portion.
256 * This emulates PuTTY's default clear screen behavior.
257 */
258 scrollOnEraseInDisplay?: boolean;
259
260 /**
261 * Whether to scroll to the bottom whenever there is some user input. The
262 * default is true.
263 */
264 scrollOnUserInput?: boolean;
265
266 /**
267 * The scrolling speed multiplier used for adjusting normal scrolling speed.
268 */
269 scrollSensitivity?: number;
270
271 /**
272 * The duration to smoothly scroll between the origin and the target in
273 * milliseconds. Set to 0 to disable smooth scrolling and scroll instantly.
274 */
275 smoothScrollDuration?: number;
276
277 /**
278 * The size of tab stops in the terminal.
279 */
280 tabStopWidth?: number;
281
282 /**
283 * The color theme of the terminal.
284 */
285 theme?: ITheme;
286
287 /**
288 * Compatibility information when the pty is known to be hosted on Windows.
289 * Setting this will turn on certain heuristics/workarounds depending on the
290 * values:
291 *
292 * - `if (backend !== undefined || buildNumber !== undefined)`
293 * - When increasing the rows in the terminal, the amount increased into
294 * the scrollback. This is done because ConPTY does not behave like
295 * expect scrollback to come back into the viewport, instead it makes
296 * empty rows at of the viewport. Not having this behavior can result in
297 * missing data as the rows get replaced.
298 * - `if !(backend === 'conpty' && buildNumber >= 21376)`
299 * - Reflow is disabled
300 * - Lines are assumed to be wrapped if the last character of the line is
301 * not whitespace.
302 */
303 windowsPty?: IWindowsPty;
304
305 /**
306 * A string containing all characters that are considered word separated by
307 * the double click to select work logic.
308 */
309 wordSeparator?: string;
310
311 /**
312 * Enable various window manipulation and report features.
313 * All features are disabled by default for security reasons.
314 */
315 windowOptions?: IWindowOptions;
316
317 /**
318 * Controls the visibility and style of the overview ruler which visualizes
319 * decorations underneath the scroll bar.
320 */
321 overviewRuler?: IOverviewRulerOptions;
322 }
323
324 /**
325 * An object containing additional options for the terminal that can only be
326 * set on start up.
327 */
328 export interface ITerminalInitOnlyOptions {
329 /**
330 * The number of columns in the terminal.
331 */
332 cols?: number;
333
334 /**
335 * The number of rows in the terminal.
336 */
337 rows?: number;
338 }
339
340 /**
341 * Contains colors to theme the terminal with.
342 */
343 export interface ITheme {
344 /** The default foreground color */
345 foreground?: string;
346 /** The default background color */
347 background?: string;
348 /** The cursor color */
349 cursor?: string;
350 /** The accent color of the cursor (fg color for a block cursor) */
351 cursorAccent?: string;
352 /** The selection background color (can be transparent) */
353 selectionBackground?: string;
354 /** The selection foreground color */
355 selectionForeground?: string;
356 /**
357 * The selection background color when the terminal does not have focus (can
358 * be transparent)
359 */
360 selectionInactiveBackground?: string;
361 /**
362 * The scrollbar slider background color. Defaults to
363 * {@link ITerminalOptions.foreground foreground} with 20% opacity.
364 */
365 scrollbarSliderBackground?: string;
366 /**
367 * The scrollbar slider background color when hovered. Defaults to
368 * {@link ITerminalOptions.foreground foreground} with 40% opacity.
369 */
370 scrollbarSliderHoverBackground?: string;
371 /**
372 * The scrollbar slider background color when clicked. Defaults to
373 * {@link ITerminalOptions.foreground foreground} with 50% opacity.
374 */
375 scrollbarSliderActiveBackground?: string;
376 /**
377 * The border color of the overview ruler. This visually separates the
378 * terminal from the scroll bar when {@link IOverviewRulerOptions.width} is
379 * set. When this is not set it defaults to black (`#000000`).
380 */
381 overviewRulerBorder?: string;
382 /** ANSI black (eg. `\x1b[30m`) */
383 black?: string;
384 /** ANSI red (eg. `\x1b[31m`) */
385 red?: string;
386 /** ANSI green (eg. `\x1b[32m`) */
387 green?: string;
388 /** ANSI yellow (eg. `\x1b[33m`) */
389 yellow?: string;
390 /** ANSI blue (eg. `\x1b[34m`) */
391 blue?: string;
392 /** ANSI magenta (eg. `\x1b[35m`) */
393 magenta?: string;
394 /** ANSI cyan (eg. `\x1b[36m`) */
395 cyan?: string;
396 /** ANSI white (eg. `\x1b[37m`) */
397 white?: string;
398 /** ANSI bright black (eg. `\x1b[1;30m`) */
399 brightBlack?: string;
400 /** ANSI bright red (eg. `\x1b[1;31m`) */
401 brightRed?: string;
402 /** ANSI bright green (eg. `\x1b[1;32m`) */
403 brightGreen?: string;
404 /** ANSI bright yellow (eg. `\x1b[1;33m`) */
405 brightYellow?: string;
406 /** ANSI bright blue (eg. `\x1b[1;34m`) */
407 brightBlue?: string;
408 /** ANSI bright magenta (eg. `\x1b[1;35m`) */
409 brightMagenta?: string;
410 /** ANSI bright cyan (eg. `\x1b[1;36m`) */
411 brightCyan?: string;
412 /** ANSI bright white (eg. `\x1b[1;37m`) */
413 brightWhite?: string;
414 /** ANSI extended colors (16-255) */
415 extendedAnsi?: string[];
416 }
417
418 /**
419 * Pty information for Windows.
420 */
421 export interface IWindowsPty {
422 /**
423 * What pty emulation backend is being used.
424 */
425 backend?: 'conpty' | 'winpty';
426 /**
427 * The Windows build version (eg. 19045)
428 */
429 buildNumber?: number;
430 }
431
432 /**
433 * A replacement logger for `console`.
434 */
435 export interface ILogger {
436 /**
437 * Log a trace message, this will only be called if
438 * {@link ITerminalOptions.logLevel} is set to trace.
439 */
440 trace(message: string, ...args: any[]): void;
441 /**
442 * Log a debug message, this will only be called if
443 * {@link ITerminalOptions.logLevel} is set to debug or below.
444 */
445 debug(message: string, ...args: any[]): void;
446 /**
447 * Log a debug message, this will only be called if
448 * {@link ITerminalOptions.logLevel} is set to info or below.
449 */
450 info(message: string, ...args: any[]): void;
451 /**
452 * Log a debug message, this will only be called if
453 * {@link ITerminalOptions.logLevel} is set to warn or below.
454 */
455 warn(message: string, ...args: any[]): void;
456 /**
457 * Log a debug message, this will only be called if
458 * {@link ITerminalOptions.logLevel} is set to error or below.
459 */
460 error(message: string | Error, ...args: any[]): void;
461 }
462
463 /**
464 * An object that can be disposed via a dispose function.
465 */
466 export interface IDisposable {
467 dispose(): void;
468 }
469
470 /**
471 * An event that can be listened to.
472 * @returns an `IDisposable` to stop listening.
473 */
474 export interface IEvent<T, U = void> {
475 (listener: (arg1: T, arg2: U) => any): IDisposable;
476 }
477
478 /**
479 * Represents a specific line in the terminal that is tracked when scrollback
480 * is trimmed and lines are added or removed. This is a single line that may
481 * be part of a larger wrapped line.
482 */
483 export interface IMarker extends IDisposableWithEvent {
484 /**
485 * A unique identifier for this marker.
486 */
487 readonly id: number;
488
489 /**
490 * The actual line index in the buffer at this point in time. This is set to
491 * -1 if the marker has been disposed.
492 */
493 readonly line: number;
494 }
495
496 /**
497 * Represents a disposable that tracks is disposed state.
498 */
499 export interface IDisposableWithEvent extends IDisposable {
500 /**
501 * Event listener to get notified when this gets disposed.
502 */
503 onDispose: IEvent<void>;
504
505 /**
506 * Whether this is disposed.
507 */
508 readonly isDisposed: boolean;
509 }
510
511 /**
512 * Represents a decoration in the terminal that is associated with a
513 * particular marker and DOM element.
514 */
515 export interface IDecoration extends IDisposableWithEvent {
516 /*
517 * The marker for the decoration in the terminal.
518 */
519 readonly marker: IMarker;
520
521 /**
522 * An event fired when the decoration
523 * is rendered, returns the dom element
524 * associated with the decoration.
525 */
526 readonly onRender: IEvent<HTMLElement>;
527
528 /**
529 * The element that the decoration is rendered to. This will be undefined
530 * until it is rendered for the first time by {@link IDecoration.onRender}.
531 * that.
532 */
533 element: HTMLElement | undefined;
534
535 /**
536 * The options for the overview ruler that can be updated. This will only
537 * take effect when {@link IDecorationOptions.overviewRulerOptions} were
538 * provided initially.
539 */
540 options: Pick<IDecorationOptions, 'overviewRulerOptions'>;
541 }
542
543
544 /**
545 * Overview ruler decoration options
546 */
547 interface IDecorationOverviewRulerOptions {
548 color: string;
549 position?: 'left' | 'center' | 'right' | 'full';
550 }
551
552 /*
553 * Options that define the presentation of the decoration.
554 */
555 export interface IDecorationOptions {
556 /**
557 * The line in the terminal where
558 * the decoration will be displayed
559 */
560 readonly marker: IMarker;
561
562 /*
563 * Where the decoration will be anchored -
564 * defaults to the left edge
565 */
566 readonly anchor?: 'right' | 'left';
567
568 /**
569 * The x position offset relative to the anchor
570 */
571 readonly x?: number;
572
573
574 /**
575 * The width of the decoration in cells, defaults to 1.
576 */
577 readonly width?: number;
578
579 /**
580 * The height of the decoration in cells, defaults to 1.
581 */
582 readonly height?: number;
583
584 /**
585 * The background color of the cell(s). When 2 decorations both set the
586 * foreground color the last registered decoration will be used. Only the
587 * `#RRGGBB` format is supported.
588 */
589 readonly backgroundColor?: string;
590
591 /**
592 * The foreground color of the cell(s). When 2 decorations both set the
593 * foreground color the last registered decoration will be used. Only the
594 * `#RRGGBB` format is supported.
595 */
596 readonly foregroundColor?: string;
597
598 /**
599 * What layer to render the decoration at when {@link backgroundColor} or
600 * {@link foregroundColor} are used. `'bottom'` will render under the
601 * selection, `'top`' will render above the selection\*.
602 */
603 readonly layer?: 'bottom' | 'top';
604
605 /**
606 * When defined, renders the decoration in the overview ruler to the right
607 * of the terminal. {@link IOverviewRulerOptions.width} must be set in order
608 * to see the overview ruler.
609 * @param color The color of the decoration.
610 * @param position The position of the decoration.
611 */
612 overviewRulerOptions?: IDecorationOverviewRulerOptions;
613 }
614
615 /**
616 * The set of localizable strings.
617 */
618 export interface ILocalizableStrings {
619 /**
620 * The aria label for the underlying input textarea for the terminal.
621 */
622 promptLabel: string;
623
624 /**
625 * Announcement for when line reading is suppressed due to too many lines
626 * being printed to the terminal when `screenReaderMode` is enabled.
627 */
628 tooMuchOutput: string;
629 }
630
631 export interface IOverviewRulerOptions {
632 /**
633 * When defined, renders decorations in the overview ruler to the right of
634 * the terminal. This must be set in order to see the overview ruler.
635 * @param color The color of the decoration.
636 * @param position The position of the decoration.
637 */
638 width?: number;
639
640 /**
641 * Whether to show the top border of the overview ruler, which uses the
642 * {@link ITheme.overviewRulerBorder} color.
643 */
644 showTopBorder?: boolean;
645
646 /**
647 * Whether to show the bottom border of the overview ruler, which uses the
648 * {@link ITheme.overviewRulerBorder} color.
649 */
650 showBottomBorder?: boolean;
651 }
652
653 /**
654 * Enable various window manipulation and report features
655 * (`CSI Ps ; Ps ; Ps t`).
656 *
657 * Most settings have no default implementation, as they heavily rely on
658 * the embedding environment.
659 *
660 * To implement a feature, create a custom CSI hook like this:
661 * ```ts
662 * term.parser.addCsiHandler({final: 't'}, params => {
663 * const ps = params[0];
664 * switch (ps) {
665 * case XY:
666 * ... // your implementation for option XY
667 * return true; // signal Ps=XY was handled
668 * }
669 * return false; // any Ps that was not handled
670 * });
671 * ```
672 *
673 * Note on security:
674 * Most features are meant to deal with some information of the host machine
675 * where the terminal runs on. This is seen as a security risk possibly
676 * leaking sensitive data of the host to the program in the terminal.
677 * Therefore all options (even those without a default implementation) are
678 * guarded by the boolean flag and disabled by default.
679 */
680 export interface IWindowOptions {
681 /**
682 * Ps=1 De-iconify window.
683 * No default implementation.
684 */
685 restoreWin?: boolean;
686 /**
687 * Ps=2 Iconify window.
688 * No default implementation.
689 */
690 minimizeWin?: boolean;
691 /**
692 * Ps=3 ; x ; y
693 * Move window to [x, y].
694 * No default implementation.
695 */
696 setWinPosition?: boolean;
697 /**
698 * Ps = 4 ; height ; width
699 * Resize the window to given `height` and `width` in pixels.
700 * Omitted parameters should reuse the current height or width.
701 * Zero parameters should use the display's height or width.
702 * No default implementation.
703 */
704 setWinSizePixels?: boolean;
705 /**
706 * Ps=5 Raise the window to the front of the stacking order.
707 * No default implementation.
708 */
709 raiseWin?: boolean;
710 /**
711 * Ps=6 Lower the xterm window to the bottom of the stacking order.
712 * No default implementation.
713 */
714 lowerWin?: boolean;
715 /** Ps=7 Refresh the window. */
716 refreshWin?: boolean;
717 /**
718 * Ps = 8 ; height ; width
719 * Resize the text area to given height and width in characters.
720 * Omitted parameters should reuse the current height or width.
721 * Zero parameters use the display's height or width.
722 * No default implementation.
723 */
724 setWinSizeChars?: boolean;
725 /**
726 * Ps=9 ; 0 Restore maximized window.
727 * Ps=9 ; 1 Maximize window (i.e., resize to screen size).
728 * Ps=9 ; 2 Maximize window vertically.
729 * Ps=9 ; 3 Maximize window horizontally.
730 * No default implementation.
731 */
732 maximizeWin?: boolean;
733 /**
734 * Ps=10 ; 0 Undo full-screen mode.
735 * Ps=10 ; 1 Change to full-screen.
736 * Ps=10 ; 2 Toggle full-screen.
737 * No default implementation.
738 */
739 fullscreenWin?: boolean;
740 /** Ps=11 Report xterm window state.
741 * If the xterm window is non-iconified, it returns "CSI 1 t".
742 * If the xterm window is iconified, it returns "CSI 2 t".
743 * No default implementation.
744 */
745 getWinState?: boolean;
746 /**
747 * Ps=13 Report xterm window position. Result is "CSI 3 ; x ; y t".
748 * Ps=13 ; 2 Report xterm text-area position. Result is "CSI 3 ; x ; y t".
749 * No default implementation.
750 */
751 getWinPosition?: boolean;
752 /**
753 * Ps=14 Report xterm text area size in pixels. Result is "CSI 4 ; height ; width t".
754 * Ps=14 ; 2 Report xterm window size in pixels. Result is "CSI 4 ; height ; width t".
755 * Has a default implementation.
756 */
757 getWinSizePixels?: boolean;
758 /**
759 * Ps=15 Report size of the screen in pixels. Result is "CSI 5 ; height ; width t".
760 * No default implementation.
761 */
762 getScreenSizePixels?: boolean;
763 /**
764 * Ps=16 Report xterm character cell size in pixels. Result is "CSI 6 ; height ; width t".
765 * Has a default implementation.
766 */
767 getCellSizePixels?: boolean;
768 /**
769 * Ps=18 Report the size of the text area in characters. Result is "CSI 8 ; height ; width t".
770 * Has a default implementation.
771 */
772 getWinSizeChars?: boolean;
773 /**
774 * Ps=19 Report the size of the screen in characters. Result is "CSI 9 ; height ; width t".
775 * No default implementation.
776 */
777 getScreenSizeChars?: boolean;
778 /**
779 * Ps=20 Report xterm window's icon label. Result is "OSC L label ST".
780 * No default implementation.
781 */
782 getIconTitle?: boolean;
783 /**
784 * Ps=21 Report xterm window's title. Result is "OSC l label ST".
785 * No default implementation.
786 */
787 getWinTitle?: boolean;
788 /**
789 * Ps=22 ; 0 Save xterm icon and window title on stack.
790 * Ps=22 ; 1 Save xterm icon title on stack.
791 * Ps=22 ; 2 Save xterm window title on stack.
792 * All variants have a default implementation.
793 */
794 pushTitle?: boolean;
795 /**
796 * Ps=23 ; 0 Restore xterm icon and window title from stack.
797 * Ps=23 ; 1 Restore xterm icon title from stack.
798 * Ps=23 ; 2 Restore xterm window title from stack.
799 * All variants have a default implementation.
800 */
801 popTitle?: boolean;
802 /**
803 * Ps>=24 Resize to Ps lines (DECSLPP).
804 * DECSLPP is not implemented. This settings is also used to
805 * enable / disable DECCOLM (earlier variant of DECSLPP).
806 */
807 setWinLines?: boolean;
808 }
809
810 /**
811 * The class that represents an xterm.js terminal.
812 */
813 export class Terminal implements IDisposable {
814 /**
815 * The element containing the terminal.
816 */
817 readonly element: HTMLElement | undefined;
818
819 /**
820 * The textarea that accepts input for the terminal.
821 */
822 readonly textarea: HTMLTextAreaElement | undefined;
823
824 /**
825 * The number of rows in the terminal's viewport. Use
826 * `ITerminalOptions.rows` to set this in the constructor and
827 * `Terminal.resize` for when the terminal exists.
828 */
829 readonly rows: number;
830
831 /**
832 * The number of columns in the terminal's viewport. Use
833 * `ITerminalOptions.cols` to set this in the constructor and
834 * `Terminal.resize` for when the terminal exists.
835 */
836 readonly cols: number;
837
838 /**
839 * Access to the terminal's normal and alt buffer.
840 */
841 readonly buffer: IBufferNamespace;
842
843 /**
844 * (EXPERIMENTAL) Get all markers registered against the buffer. If the alt
845 * buffer is active this will always return [].
846 */
847 readonly markers: ReadonlyArray<IMarker>;
848
849 /**
850 * Get the parser interface to register custom escape sequence handlers.
851 */
852 readonly parser: IParser;
853
854 /**
855 * (EXPERIMENTAL) Get the Unicode handling interface
856 * to register and switch Unicode version.
857 */
858 readonly unicode: IUnicodeHandling;
859
860 /**
861 * Gets the terminal modes as set by SM/DECSET.
862 */
863 readonly modes: IModes;
864
865 /**
866 * Gets or sets the terminal options. This supports setting multiple
867 * options.
868 *
869 * @example Get a single option
870 * ```ts
871 * console.log(terminal.options.fontSize);
872 * ```
873 *
874 * @example Set a single option:
875 * ```ts
876 * terminal.options.fontSize = 12;
877 * ```
878 * Note that for options that are object, a new object must be used in order
879 * to take effect as a reference comparison will be done:
880 * ```ts
881 * const newValue = terminal.options.theme;
882 * newValue.background = '#000000';
883 *
884 * // This won't work
885 * terminal.options.theme = newValue;
886 *
887 * // This will work
888 * terminal.options.theme = { ...newValue };
889 * ```
890 *
891 * @example Set multiple options
892 * ```ts
893 * terminal.options = {
894 * fontSize: 12,
895 * fontFamily: 'Courier New'
896 * };
897 * ```
898 */
899 options: ITerminalOptions;
900
901 /**
902 * Natural language strings that can be localized.
903 */
904 static strings: ILocalizableStrings;
905
906 /**
907 * Creates a new `Terminal` object.
908 *
909 * @param options An object containing a set of options.
910 */
911 constructor(options?: ITerminalOptions & ITerminalInitOnlyOptions);
912
913 /**
914 * Adds an event listener for when the bell is triggered.
915 * @returns an `IDisposable` to stop listening.
916 */
917 onBell: IEvent<void>;
918
919 /**
920 * Adds an event listener for when a binary event fires. This is used to
921 * enable non UTF-8 conformant binary messages to be sent to the backend.
922 * Currently this is only used for a certain type of mouse reports that
923 * happen to be not UTF-8 compatible.
924 * The event value is a JS string, pass it to the underlying pty as
925 * binary data, e.g. `pty.write(Buffer.from(data, 'binary'))`.
926 * @returns an `IDisposable` to stop listening.
927 */
928 onBinary: IEvent<string>;
929
930 /**
931 * Adds an event listener for the cursor moves.
932 * @returns an `IDisposable` to stop listening.
933 */
934 onCursorMove: IEvent<void>;
935
936 /**
937 * Adds an event listener for when a data event fires. This happens for
938 * example when the user types or pastes into the terminal. The event value
939 * is whatever `string` results, in a typical setup, this should be passed
940 * on to the backing pty.
941 * @returns an `IDisposable` to stop listening.
942 */
943 onData: IEvent<string>;
944
945 /**
946 * Adds an event listener for when a key is pressed. The event value
947 * contains the string that will be sent in the data event as well as the
948 * DOM event that triggered it.
949 * @returns an `IDisposable` to stop listening.
950 */
951 onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
952
953 /**
954 * Adds an event listener for when a line feed is added.
955 * @returns an `IDisposable` to stop listening.
956 */
957 onLineFeed: IEvent<void>;
958
959 /**
960 * Adds an event listener for when rows are rendered. The event value
961 * contains the start row and end rows of the rendered area (ranges from `0`
962 * to `Terminal.rows - 1`).
963 * @returns an `IDisposable` to stop listening.
964 */
965 onRender: IEvent<{ start: number, end: number }>;
966
967 /**
968 * Adds an event listener for when data has been parsed by the terminal,
969 * after {@link write} is called. This event is useful to listen for any
970 * changes in the buffer.
971 *
972 * This fires at most once per frame, after data parsing completes. Note
973 * that this can fire when there are still writes pending if there is a lot
974 * of data.
975 */
976 onWriteParsed: IEvent<void>;
977
978 /**
979 * Adds an event listener for when the terminal is resized. The event value
980 * contains the new size.
981 * @returns an `IDisposable` to stop listening.
982 */
983 onResize: IEvent<{ cols: number, rows: number }>;
984
985 /**
986 * Adds an event listener for when a scroll occurs. The event value is the
987 * new position of the viewport.
988 * @returns an `IDisposable` to stop listening.
989 */
990 onScroll: IEvent<number>;
991
992 /**
993 * Adds an event listener for when a selection change occurs.
994 * @returns an `IDisposable` to stop listening.
995 */
996 onSelectionChange: IEvent<void>;
997
998 /**
999 * Adds an event listener for when an OSC 0 or OSC 2 title change occurs.
1000 * The event value is the new title.
1001 * @returns an `IDisposable` to stop listening.
1002 */
1003 onTitleChange: IEvent<string>;
1004
1005 /**
1006 * Unfocus the terminal.
1007 */
1008 blur(): void;
1009
1010 /**
1011 * Focus the terminal.
1012 */
1013 focus(): void;
1014
1015 /**
1016 * Input data to application side. The data is treated the same way input
1017 * typed into the terminal would (ie. the {@link onData} event will fire).
1018 * @param data The data to forward to the application.
1019 * @param wasUserInput Whether the input is genuine user input. This is true
1020 * by default and triggers additionalbehavior like focus or selection
1021 * clearing. Set this to false if the data sent should not be treated like
1022 * user input would, for example passing an escape sequence to the
1023 * application.
1024 */
1025 input(data: string, wasUserInput?: boolean): void;
1026
1027 /**
1028 * Resizes the terminal. It's best practice to debounce calls to resize,
1029 * this will help ensure that the pty can respond to the resize event
1030 * before another one occurs.
1031 * @param x The number of columns to resize to.
1032 * @param y The number of rows to resize to.
1033 */
1034 resize(columns: number, rows: number): void;
1035
1036 /**
1037 * Opens the terminal within an element. This should also be called if the
1038 * xterm.js element ever changes browser window.
1039 * @param parent The element to create the terminal within. This element
1040 * must be visible (have dimensions) when `open` is called as several DOM-
1041 * based measurements need to be performed when this function is called.
1042 */
1043 open(parent: HTMLElement): void;
1044
1045 /**
1046 * Attaches a custom key event handler which is run before keys are
1047 * processed, giving consumers of xterm.js ultimate control as to what keys
1048 * should be processed by the terminal and what keys should not.
1049 * @param customKeyEventHandler The custom KeyboardEvent handler to attach.
1050 * This is a function that takes a KeyboardEvent, allowing consumers to stop
1051 * propagation and/or prevent the default action. The function returns
1052 * whether the event should be processed by xterm.js.
1053 *
1054 * @example A custom keymap that overrides the backspace key
1055 * ```ts
1056 * const keymap = [
1057 * { "key": "Backspace", "shiftKey": false, "mapCode": 8 },
1058 * { "key": "Backspace", "shiftKey": true, "mapCode": 127 }
1059 * ];
1060 * term.attachCustomKeyEventHandler(ev => {
1061 * if (ev.type === 'keydown') {
1062 * for (let i in keymap) {
1063 * if (keymap[i].key == ev.key && keymap[i].shiftKey == ev.shiftKey) {
1064 * socket.send(String.fromCharCode(keymap[i].mapCode));
1065 * return false;
1066 * }
1067 * }
1068 * }
1069 * });
1070 * ```
1071 */
1072 attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
1073
1074 /**
1075 * Attaches a custom wheel event handler which is run before keys are
1076 * processed, giving consumers of xterm.js control over whether to proceed
1077 * or cancel terminal wheel events.
1078 * @param customWheelEventHandler The custom WheelEvent handler to attach.
1079 * This is a function that takes a WheelEvent, allowing consumers to stop
1080 * propagation and/or prevent the default action. The function returns
1081 * whether the event should be processed by xterm.js.
1082 *
1083 * @example A handler that prevents all wheel events while ctrl is held from
1084 * being processed.
1085 * ```ts
1086 * term.attachCustomWheelEventHandler(ev => {
1087 * if (ev.ctrlKey) {
1088 * return false;
1089 * }
1090 * return true;
1091 * });
1092 * ```
1093 */
1094 attachCustomWheelEventHandler(customWheelEventHandler: (event: WheelEvent) => boolean): void;
1095
1096 /**
1097 * Registers a link provider, allowing a custom parser to be used to match
1098 * and handle links. Multiple link providers can be used, they will be asked
1099 * in the order in which they are registered.
1100 * @param linkProvider The link provider to use to detect links.
1101 */
1102 registerLinkProvider(linkProvider: ILinkProvider): IDisposable;
1103
1104 /**
1105 * (EXPERIMENTAL) Registers a character joiner, allowing custom sequences of
1106 * characters to be rendered as a single unit. This is useful in particular
1107 * for rendering ligatures and graphemes, among other things.
1108 *
1109 * Each registered character joiner is called with a string of text
1110 * representing a portion of a line in the terminal that can be rendered as
1111 * a single unit. The joiner must return a sorted array, where each entry is
1112 * itself an array of length two, containing the start (inclusive) and end
1113 * (exclusive) index of a substring of the input that should be rendered as
1114 * a single unit. When multiple joiners are provided, the results of each
1115 * are collected. If there are any overlapping substrings between them, they
1116 * are combined into one larger unit that is drawn together.
1117 *
1118 * All character joiners that are registered get called every time a line is
1119 * rendered in the terminal, so it is essential for the handler function to
1120 * run as quickly as possible to avoid slowdowns when rendering. Similarly,
1121 * joiners should strive to return the smallest possible substrings to
1122 * render together, since they aren't drawn as optimally as individual
1123 * characters.
1124 *
1125 * NOTE: character joiners are only used by the webgl renderer.
1126 *
1127 * @param handler The function that determines character joins. It is called
1128 * with a string of text that is eligible for joining and returns an array
1129 * where each entry is an array containing the start (inclusive) and end
1130 * (exclusive) indexes of ranges that should be rendered as a single unit.
1131 * @returns The ID of the new joiner, this can be used to deregister
1132 */
1133 registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
1134
1135 /**
1136 * (EXPERIMENTAL) Deregisters the character joiner if one was registered.
1137 * NOTE: character joiners are only used by the webgl renderer.
1138 * @param joinerId The character joiner's ID (returned after register)
1139 */
1140 deregisterCharacterJoiner(joinerId: number): void;
1141
1142 /**
1143 * Adds a marker to the normal buffer and returns it.
1144 * @param cursorYOffset The y position offset of the marker from the cursor.
1145 * @returns The new marker or undefined.
1146 */
1147 registerMarker(cursorYOffset?: number): IMarker;
1148
1149 /**
1150 * (EXPERIMENTAL) Adds a decoration to the terminal using
1151 * @param decorationOptions, which takes a marker and an optional anchor,
1152 * width, height, and x offset from the anchor. Returns the decoration or
1153 * undefined if the alt buffer is active or the marker has already been
1154 * disposed of.
1155 * @throws when options include a negative x offset.
1156 */
1157 registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined;
1158
1159 /**
1160 * Gets whether the terminal has an active selection.
1161 */
1162 hasSelection(): boolean;
1163
1164 /**
1165 * Gets the terminal's current selection, this is useful for implementing
1166 * copy behavior outside of xterm.js.
1167 */
1168 getSelection(): string;
1169
1170 /**
1171 * Gets the selection position or undefined if there is no selection.
1172 */
1173 getSelectionPosition(): IBufferRange | undefined;
1174
1175 /**
1176 * Clears the current terminal selection.
1177 */
1178 clearSelection(): void;
1179
1180 /**
1181 * Selects text within the terminal.
1182 * @param column The column the selection starts at.
1183 * @param row The row the selection starts at.
1184 * @param length The length of the selection.
1185 */
1186 select(column: number, row: number, length: number): void;
1187
1188 /**
1189 * Selects all text within the terminal.
1190 */
1191 selectAll(): void;
1192
1193 /**
1194 * Selects text in the buffer between 2 lines.
1195 * @param start The 0-based line index to select from (inclusive).
1196 * @param end The 0-based line index to select to (inclusive).
1197 */
1198 selectLines(start: number, end: number): void;
1199
1200 /*
1201 * Disposes of the terminal, detaching it from the DOM and removing any
1202 * active listeners. Once the terminal is disposed it should not be used
1203 * again.
1204 */
1205 dispose(): void;
1206
1207 /**
1208 * Scroll the display of the terminal
1209 * @param amount The number of lines to scroll down (negative scroll up).
1210 */
1211 scrollLines(amount: number): void;
1212
1213 /**
1214 * Scroll the display of the terminal by a number of pages.
1215 * @param pageCount The number of pages to scroll (negative scrolls up).
1216 */
1217 scrollPages(pageCount: number): void;
1218
1219 /**
1220 * Scrolls the display of the terminal to the top.
1221 */
1222 scrollToTop(): void;
1223
1224 /**
1225 * Scrolls the display of the terminal to the bottom.
1226 */
1227 scrollToBottom(): void;
1228
1229 /**
1230 * Scrolls to a line within the buffer.
1231 * @param line The 0-based line index to scroll to.
1232 */
1233 scrollToLine(line: number): void;
1234
1235 /**
1236 * Clear the entire buffer, making the prompt line the new first line.
1237 */
1238 clear(): void;
1239
1240 /**
1241 * Write data to the terminal.
1242 *
1243 * Note that the change will not be reflected in the {@link buffer}
1244 * immediately as the data is processed asynchronously. Provide a
1245 * {@link callback} to know when the data was processed.
1246 * @param data The data to write to the terminal. This can either be raw
1247 * bytes given as Uint8Array from the pty or a string. Raw bytes will always
1248 * be treated as UTF-8 encoded, string data as UTF-16.
1249 * @param callback Optional callback that fires when the data was processed
1250 * by the parser. This callback must be provided and awaited in order for
1251 * {@link buffer} to reflect the change in the write.
1252 */
1253 write(data: string | Uint8Array, callback?: () => void): void;
1254
1255 /**
1256 * Writes data to the terminal, followed by a break line character (\n).
1257 *
1258 * Note that the change will not be reflected in the {@link buffer}
1259 * immediately as the data is processed asynchronously. Provide a
1260 * {@link callback} to know when the data was processed.
1261 * @param data The data to write to the terminal. This can either be raw
1262 * bytes given as Uint8Array from the pty or a string. Raw bytes will always
1263 * be treated as UTF-8 encoded, string data as UTF-16.
1264 * @param callback Optional callback that fires when the data was processed
1265 * by the parser. This callback must be provided and awaited in order for
1266 * {@link buffer} to reflect the change in the write.
1267 */
1268 writeln(data: string | Uint8Array, callback?: () => void): void;
1269
1270 /**
1271 * Writes text to the terminal, performing the necessary transformations for
1272 * pasted text.
1273 * @param data The text to write to the terminal.
1274 */
1275 paste(data: string): void;
1276
1277 /**
1278 * Tells the renderer to refresh terminal content between two rows
1279 * (inclusive) at the next opportunity.
1280 * @param start The row to start from (between 0 and this.rows - 1).
1281 * @param end The row to end at (between start and this.rows - 1).
1282 */
1283 refresh(start: number, end: number): void;
1284
1285 /**
1286 * Clears the texture atlas of the webgl renderer if it's active. Doing
1287 * this will force a redraw of all glyphs which can workaround issues
1288 * causing the texture to become corrupt, for example Chromium/Nvidia has an
1289 * issue where the texture gets messed up when resuming the OS from sleep.
1290 */
1291 clearTextureAtlas(): void;
1292
1293 /**
1294 * Perform a full reset (RIS, aka '\x1bc').
1295 */
1296 reset(): void;
1297
1298 /**
1299 * Loads an addon into this instance of xterm.js.
1300 * @param addon The addon to load.
1301 */
1302 loadAddon(addon: ITerminalAddon): void;
1303 }
1304
1305 /**
1306 * An addon that can provide additional functionality to the terminal.
1307 */
1308 export interface ITerminalAddon extends IDisposable {
1309 /**
1310 * This is called when the addon is activated.
1311 */
1312 activate(terminal: Terminal): void;
1313 }
1314
1315 /**
1316 * An object representing a range within the viewport of the terminal.
1317 */
1318 export interface IViewportRange {
1319 /**
1320 * The start of the range.
1321 */
1322 start: IViewportRangePosition;
1323
1324 /**
1325 * The end of the range.
1326 */
1327 end: IViewportRangePosition;
1328 }
1329
1330 /**
1331 * An object representing a cell position within the viewport of the terminal.
1332 */
1333 interface IViewportRangePosition {
1334 /**
1335 * The x position of the cell. This is a 0-based index that refers to the
1336 * space in between columns, not the column itself. Index 0 refers to the
1337 * left side of the viewport, index `Terminal.cols` refers to the right side
1338 * of the viewport. This can be thought of as how a cursor is positioned in
1339 * a text editor.
1340 */
1341 x: number;
1342
1343 /**
1344 * The y position of the cell. This is a 0-based index that refers to a
1345 * specific row.
1346 */
1347 y: number;
1348 }
1349
1350 /**
1351 * A link handler for OSC 8 hyperlinks.
1352 */
1353 interface ILinkHandler {
1354 /**
1355 * Calls when the link is activated.
1356 * @param event The mouse event triggering the callback.
1357 * @param text The text of the link.
1358 * @param range The buffer range of the link.
1359 */
1360 activate(event: MouseEvent, text: string, range: IBufferRange): void;
1361
1362 /**
1363 * Called when the mouse hovers the link. To use this to create a DOM-based
1364 * hover tooltip, create the hover element within `Terminal.element` and
1365 * add the `xterm-hover` class to it, that will cause mouse events to not
1366 * fall through and activate other links.
1367 * @param event The mouse event triggering the callback.
1368 * @param text The text of the link.
1369 * @param range The buffer range of the link.
1370 */
1371 hover?(event: MouseEvent, text: string, range: IBufferRange): void;
1372
1373 /**
1374 * Called when the mouse leaves the link.
1375 * @param event The mouse event triggering the callback.
1376 * @param text The text of the link.
1377 * @param range The buffer range of the link.
1378 */
1379 leave?(event: MouseEvent, text: string, range: IBufferRange): void;
1380
1381 /**
1382 * Whether to receive non-HTTP URLs from LinkProvider. When false, any
1383 * usage of non-HTTP URLs will be ignored. Enabling this option without
1384 * proper protection in `activate` function may cause security issues such
1385 * as XSS.
1386 */
1387 allowNonHttpProtocols?: boolean;
1388 }
1389
1390 /**
1391 * A custom link provider.
1392 */
1393 interface ILinkProvider {
1394 /**
1395 * Provides a link a buffer position
1396 * @param bufferLineNumber The y position of the buffer to check for links
1397 * within.
1398 * @param callback The callback to be fired when ready with the resulting
1399 * link(s) for the line or `undefined`.
1400 */
1401 provideLinks(bufferLineNumber: number, callback: (links: ILink[] | undefined) => void): void;
1402 }
1403
1404 /**
1405 * A link within the terminal.
1406 */
1407 interface ILink {
1408 /**
1409 * The buffer range of the link.
1410 */
1411 range: IBufferRange;
1412
1413 /**
1414 * The text of the link.
1415 */
1416 text: string;
1417
1418 /**
1419 * What link decorations to show when hovering the link, this property is
1420 * tracked and changes made after the link is provided will trigger changes.
1421 * If not set, all decroations will be enabled.
1422 */
1423 decorations?: ILinkDecorations;
1424
1425 /**
1426 * Calls when the link is activated.
1427 * @param event The mouse event triggering the callback.
1428 * @param text The text of the link.
1429 */
1430 activate(event: MouseEvent, text: string): void;
1431
1432 /**
1433 * Called when the mouse hovers the link. To use this to create a DOM-based
1434 * hover tooltip, create the hover element within `Terminal.element` and add
1435 * the `xterm-hover` class to it, that will cause mouse events to not fall
1436 * through and activate other links.
1437 * @param event The mouse event triggering the callback.
1438 * @param text The text of the link.
1439 */
1440 hover?(event: MouseEvent, text: string): void;
1441
1442 /**
1443 * Called when the mouse leaves the link.
1444 * @param event The mouse event triggering the callback.
1445 * @param text The text of the link.
1446 */
1447 leave?(event: MouseEvent, text: string): void;
1448
1449 /**
1450 * Called when the link is released and no longer used by xterm.js.
1451 */
1452 dispose?(): void;
1453 }
1454
1455 /**
1456 * A set of decorations that can be applied to links.
1457 */
1458 interface ILinkDecorations {
1459 /**
1460 * Whether the cursor is set to pointer.
1461 */
1462 pointerCursor: boolean;
1463
1464 /**
1465 * Whether the underline is visible
1466 */
1467 underline: boolean;
1468 }
1469
1470 /**
1471 * A range within a buffer.
1472 */
1473 interface IBufferRange {
1474 /**
1475 * The start position of the range.
1476 */
1477 start: IBufferCellPosition;
1478
1479 /**
1480 * The end position of the range.
1481 */
1482 end: IBufferCellPosition;
1483 }
1484
1485 /**
1486 * A position within a buffer.
1487 */
1488 interface IBufferCellPosition {
1489 /**
1490 * The x position within the buffer (1-based).
1491 */
1492 x: number;
1493
1494 /**
1495 * The y position within the buffer (1-based).
1496 */
1497 y: number;
1498 }
1499
1500 /**
1501 * Represents a terminal buffer.
1502 */
1503 interface IBuffer {
1504 /**
1505 * The type of the buffer.
1506 */
1507 readonly type: 'normal' | 'alternate';
1508
1509 /**
1510 * The y position of the cursor. This ranges between `0` (when the
1511 * cursor is at baseY) and `Terminal.rows - 1` (when the cursor is on the
1512 * last row).
1513 */
1514 readonly cursorY: number;
1515
1516 /**
1517 * The x position of the cursor. This ranges between `0` (left side) and
1518 * `Terminal.cols` (after last cell of the row).
1519 */
1520 readonly cursorX: number;
1521
1522 /**
1523 * The line within the buffer where the top of the viewport is.
1524 */
1525 readonly viewportY: number;
1526
1527 /**
1528 * The line within the buffer where the top of the bottom page is (when
1529 * fully scrolled down).
1530 */
1531 readonly baseY: number;
1532
1533 /**
1534 * The amount of lines in the buffer.
1535 */
1536 readonly length: number;
1537
1538 /**
1539 * Gets a line from the buffer, or undefined if the line index does not
1540 * exist.
1541 *
1542 * Note that the result of this function should be used immediately after
1543 * calling as when the terminal updates it could lead to unexpected
1544 * behavior.
1545 *
1546 * @param y The line index to get.
1547 */
1548 getLine(y: number): IBufferLine | undefined;
1549
1550 /**
1551 * Creates an empty cell object suitable as a cell reference in
1552 * `line.getCell(x, cell)`. Use this to avoid costly recreation of
1553 * cell objects when dealing with tons of cells.
1554 */
1555 getNullCell(): IBufferCell;
1556 }
1557
1558 export interface IBufferElementProvider {
1559 /**
1560 * Provides a document fragment or HTMLElement containing the buffer
1561 * elements.
1562 */
1563 provideBufferElements(): DocumentFragment | HTMLElement;
1564 }
1565
1566 /**
1567 * Represents the terminal's set of buffers.
1568 */
1569 interface IBufferNamespace {
1570 /**
1571 * The active buffer, this will either be the normal or alternate buffers.
1572 */
1573 readonly active: IBuffer;
1574
1575 /**
1576 * The normal buffer.
1577 */
1578 readonly normal: IBuffer;
1579
1580 /**
1581 * The alternate buffer, this becomes the active buffer when an application
1582 * enters this mode via DECSET (`CSI ? 4 7 h`)
1583 */
1584 readonly alternate: IBuffer;
1585
1586 /**
1587 * Adds an event listener for when the active buffer changes.
1588 * @returns an `IDisposable` to stop listening.
1589 */
1590 onBufferChange: IEvent<IBuffer>;
1591 }
1592
1593 /**
1594 * Represents a line in the terminal's buffer.
1595 */
1596 interface IBufferLine {
1597 /**
1598 * Whether the line is wrapped from the previous line.
1599 */
1600 readonly isWrapped: boolean;
1601
1602 /**
1603 * The length of the line, all call to getCell beyond the length will result
1604 * in `undefined`. Note that this may exceed columns as the line array may
1605 * not be trimmed after a resize, compare against {@link Terminal.cols} to
1606 * get the actual maximum length of a line.
1607 */
1608 readonly length: number;
1609
1610 /**
1611 * Gets a cell from the line, or undefined if the line index does not exist.
1612 *
1613 * Note that the result of this function should be used immediately after
1614 * calling as when the terminal updates it could lead to unexpected
1615 * behavior.
1616 *
1617 * @param x The character index to get.
1618 * @param cell Optional cell object to load data into for performance
1619 * reasons. This is mainly useful when every cell in the buffer is being
1620 * looped over to avoid creating new objects for every cell.
1621 */
1622 getCell(x: number, cell?: IBufferCell): IBufferCell | undefined;
1623
1624 /**
1625 * Gets the line as a string. Note that this is gets only the string for the
1626 * line, not taking isWrapped into account.
1627 *
1628 * @param trimRight Whether to trim any whitespace at the right of the line.
1629 * @param startColumn The column to start from (inclusive).
1630 * @param endColumn The column to end at (exclusive).
1631 */
1632 translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
1633 }
1634
1635 /**
1636 * Represents a single cell in the terminal's buffer.
1637 */
1638 interface IBufferCell {
1639 /**
1640 * The width of the character. Some examples:
1641 *
1642 * - `1` for most cells.
1643 * - `2` for wide character like CJK glyphs.
1644 * - `0` for cells immediately following cells with a width of `2`.
1645 */
1646 getWidth(): number;
1647
1648 /**
1649 * The character(s) within the cell. Examples of what this can contain:
1650 *
1651 * - A normal width character
1652 * - A wide character (eg. CJK)
1653 * - An emoji
1654 */
1655 getChars(): string;
1656
1657 /**
1658 * Gets the UTF32 codepoint of single characters, if content is a combined
1659 * string it returns the codepoint of the last character in the string.
1660 */
1661 getCode(): number;
1662
1663 /**
1664 * Gets the number representation of the foreground color mode, this can be
1665 * used to perform quick comparisons of 2 cells to see if they're the same.
1666 * Use `isFgRGB`, `isFgPalette` and `isFgDefault` to check what color mode
1667 * a cell is.
1668 */
1669 getFgColorMode(): number;
1670
1671 /**
1672 * Gets the number representation of the background color mode, this can be
1673 * used to perform quick comparisons of 2 cells to see if they're the same.
1674 * Use `isBgRGB`, `isBgPalette` and `isBgDefault` to check what color mode
1675 * a cell is.
1676 */
1677 getBgColorMode(): number;
1678
1679 /**
1680 * Gets a cell's foreground color number, this differs depending on what the
1681 * color mode of the cell is:
1682 *
1683 * - Default: This should be 0, representing the default foreground color
1684 * (CSI 39 m).
1685 * - Palette: This is a number from 0 to 255 of ANSI colors (CSI 3(0-7) m,
1686 * CSI 9(0-7) m, CSI 38 ; 5 ; 0-255 m).
1687 * - RGB: A hex value representing a 'true color': 0xRRGGBB.
1688 * (CSI 3 8 ; 2 ; Pi ; Pr ; Pg ; Pb)
1689 */
1690 getFgColor(): number;
1691
1692 /**
1693 * Gets a cell's background color number, this differs depending on what the
1694 * color mode of the cell is:
1695 *
1696 * - Default: This should be 0, representing the default background color
1697 * (CSI 49 m).
1698 * - Palette: This is a number from 0 to 255 of ANSI colors
1699 * (CSI 4(0-7) m, CSI 10(0-7) m, CSI 48 ; 5 ; 0-255 m).
1700 * - RGB: A hex value representing a 'true color': 0xRRGGBB
1701 * (CSI 4 8 ; 2 ; Pi ; Pr ; Pg ; Pb)
1702 */
1703 getBgColor(): number;
1704
1705 /** Whether the cell has the bold attribute (CSI 1 m). */
1706 isBold(): number;
1707 /** Whether the cell has the italic attribute (CSI 3 m). */
1708 isItalic(): number;
1709 /** Whether the cell has the dim attribute (CSI 2 m). */
1710 isDim(): number;
1711 /** Whether the cell has the underline attribute (CSI 4 m). */
1712 isUnderline(): number;
1713 /** Whether the cell has the blink attribute (CSI 5 m). */
1714 isBlink(): number;
1715 /** Whether the cell has the inverse attribute (CSI 7 m). */
1716 isInverse(): number;
1717 /** Whether the cell has the invisible attribute (CSI 8 m). */
1718 isInvisible(): number;
1719 /** Whether the cell has the strikethrough attribute (CSI 9 m). */
1720 isStrikethrough(): number;
1721 /** Whether the cell has the overline attribute (CSI 53 m). */
1722 isOverline(): number;
1723
1724 /** Whether the cell is using the RGB foreground color mode. */
1725 isFgRGB(): boolean;
1726 /** Whether the cell is using the RGB background color mode. */
1727 isBgRGB(): boolean;
1728 /** Whether the cell is using the palette foreground color mode. */
1729 isFgPalette(): boolean;
1730 /** Whether the cell is using the palette background color mode. */
1731 isBgPalette(): boolean;
1732 /** Whether the cell is using the default foreground color mode. */
1733 isFgDefault(): boolean;
1734 /** Whether the cell is using the default background color mode. */
1735 isBgDefault(): boolean;
1736
1737 /** Whether the cell has the default attribute (no color or style). */
1738 isAttributeDefault(): boolean;
1739 }
1740
1741 /**
1742 * Data type to register a CSI, DCS or ESC callback in the parser
1743 * in the form:
1744 * ESC I..I F
1745 * CSI Prefix P..P I..I F
1746 * DCS Prefix P..P I..I F data_bytes ST
1747 *
1748 * with these rules/restrictions:
1749 * - prefix can only be used with CSI and DCS
1750 * - only one leading prefix byte is recognized by the parser
1751 * before any other parameter bytes (P..P)
1752 * - intermediate bytes are recognized up to 2
1753 *
1754 * For custom sequences make sure to read ECMA-48 and the resources at
1755 * vt100.net to not clash with existing sequences or reserved address space.
1756 * General recommendations:
1757 * - use private address space (see ECMA-48)
1758 * - use max one intermediate byte (technically not limited by the spec,
1759 * in practice there are no sequences with more than one intermediate byte,
1760 * thus parsers might get confused with more intermediates)
1761 * - test against other common emulators to check whether they escape/ignore
1762 * the sequence correctly
1763 *
1764 * Notes: OSC command registration is handled differently (see addOscHandler)
1765 * APC, PM or SOS is currently not supported.
1766 */
1767 export interface IFunctionIdentifier {
1768 /**
1769 * Optional prefix byte, must be in range \x3c .. \x3f.
1770 * Usable in CSI and DCS.
1771 */
1772 prefix?: string;
1773 /**
1774 * Optional intermediate bytes, must be in range \x20 .. \x2f.
1775 * Usable in CSI, DCS and ESC.
1776 */
1777 intermediates?: string;
1778 /**
1779 * Final byte, must be in range \x40 .. \x7e for CSI and DCS,
1780 * \x30 .. \x7e for ESC.
1781 */
1782 final: string;
1783 }
1784
1785 /**
1786 * Allows hooking into the parser for custom handling of escape sequences.
1787 *
1788 * Note on sync vs. async handlers:
1789 * xterm.js implements all parser actions with synchronous handlers.
1790 * In general custom handlers should also operate in sync mode wherever
1791 * possible to keep the parser fast.
1792 * Still the exposed interfaces allow to register async handlers by returning
1793 * a `Promise<boolean>`. Here the parser will pause input processing until
1794 * the promise got resolved or rejected (in-band blocking). This "full stop"
1795 * on the input chain allows to implement backpressure from a certain async
1796 * action while the terminal state will not progress any further from input.
1797 * It does not mean that the terminal state will not change at all in between,
1798 * as user actions like resize or reset are still processed immediately.
1799 * It is an error to assume a stable terminal state while giving back control
1800 * in between, e.g. by multiple chained `then` calls.
1801 * Downside of an async handler is a rather bad throughput performance,
1802 * thus use async handlers only as a last resort or for actions that have
1803 * to rely on async interfaces itself.
1804 */
1805 export interface IParser {
1806 /**
1807 * Adds a handler for CSI escape sequences.
1808 * @param id Specifies the function identifier under which the callback gets
1809 * registered, e.g. {final: 'm'} for SGR.
1810 * @param callback The function to handle the sequence. The callback is
1811 * called with the numerical params. If the sequence has subparams the array
1812 * will contain subarrays with their numercial values. Return `true` if the
1813 * sequence was handled, `false` if the parser should try a previous
1814 * handler. The most recently added handler is tried first.
1815 * @returns An IDisposable you can call to remove this handler.
1816 */
1817 registerCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean | Promise<boolean>): IDisposable;
1818
1819 /**
1820 * Adds a handler for DCS escape sequences.
1821 * @param id Specifies the function identifier under which the callback gets
1822 * registered, e.g. {intermediates: '$' final: 'q'} for DECRQSS.
1823 * @param callback The function to handle the sequence. Note that the
1824 * function will only be called once if the sequence finished sucessfully.
1825 * There is currently no way to intercept smaller data chunks, data chunks
1826 * will be stored up until the sequence is finished. Since DCS sequences are
1827 * not limited by the amount of data this might impose a problem for big
1828 * payloads. Currently xterm.js limits DCS payload to 10 MB which should
1829 * give enough room for most use cases. The function gets the payload and
1830 * numerical parameters as arguments. Return `true` if the sequence was
1831 * handled, `false` if the parser should try a previous handler. The most
1832 * recently added handler is tried first.
1833 * @returns An IDisposable you can call to remove this handler.
1834 */
1835 registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean | Promise<boolean>): IDisposable;
1836
1837 /**
1838 * Adds a handler for ESC escape sequences.
1839 * @param id Specifies the function identifier under which the callback gets
1840 * registered, e.g. {intermediates: '%' final: 'G'} for default charset
1841 * selection.
1842 * @param callback The function to handle the sequence.
1843 * Return `true` if the sequence was handled, `false` if the parser should
1844 * try a previous handler. The most recently added handler is tried first.
1845 * @returns An IDisposable you can call to remove this handler.
1846 */
1847 registerEscHandler(id: IFunctionIdentifier, handler: () => boolean | Promise<boolean>): IDisposable;
1848
1849 /**
1850 * Adds a handler for OSC escape sequences.
1851 * @param ident The number (first parameter) of the sequence.
1852 * @param callback The function to handle the sequence. Note that the
1853 * function will only be called once if the sequence finished sucessfully.
1854 * There is currently no way to intercept smaller data chunks, data chunks
1855 * will be stored up until the sequence is finished. Since OSC sequences are
1856 * not limited by the amount of data this might impose a problem for big
1857 * payloads. Currently xterm.js limits OSC payload to 10 MB which should
1858 * give enough room for most use cases. The callback is called with OSC data
1859 * string. Return `true` if the sequence was handled, `false` if the parser
1860 * should try a previous handler. The most recently added handler is tried
1861 * first.
1862 * @returns An IDisposable you can call to remove this handler.
1863 */
1864 registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
1865 }
1866
1867 /**
1868 * (EXPERIMENTAL) Unicode version provider.
1869 * Used to register custom Unicode versions with `Terminal.unicode.register`.
1870 */
1871 export interface IUnicodeVersionProvider {
1872 /**
1873 * String indicating the Unicode version provided.
1874 */
1875 readonly version: string;
1876
1877 /**
1878 * Unicode version dependent wcwidth implementation.
1879 */
1880 wcwidth(codepoint: number): 0 | 1 | 2;
1881 charProperties(codepoint: number, preceding: number): number;
1882 }
1883
1884 /**
1885 * (EXPERIMENTAL) Unicode handling interface.
1886 */
1887 export interface IUnicodeHandling {
1888 /**
1889 * Register a custom Unicode version provider.
1890 */
1891 register(provider: IUnicodeVersionProvider): void;
1892
1893 /**
1894 * Registered Unicode versions.
1895 */
1896 readonly versions: ReadonlyArray<string>;
1897
1898 /**
1899 * Getter/setter for active Unicode version.
1900 */
1901 activeVersion: string;
1902 }
1903
1904 /**
1905 * Terminal modes as set by SM/DECSET.
1906 */
1907 export interface IModes {
1908 /**
1909 * Application Cursor Keys (DECCKM): `CSI ? 1 h`
1910 */
1911 readonly applicationCursorKeysMode: boolean;
1912 /**
1913 * Application Keypad Mode (DECNKM): `CSI ? 6 6 h`
1914 */
1915 readonly applicationKeypadMode: boolean;
1916 /**
1917 * Bracketed Paste Mode: `CSI ? 2 0 0 4 h`
1918 */
1919 readonly bracketedPasteMode: boolean;
1920 /**
1921 * Insert Mode (IRM): `CSI 4 h`
1922 */
1923 readonly insertMode: boolean;
1924 /**
1925 * Mouse Tracking, this can be one of the following:
1926 * - none: This is the default value and can be reset with DECRST
1927 * - x10: Send Mouse X & Y on button press `CSI ? 9 h`
1928 * - vt200: Send Mouse X & Y on button press and release `CSI ? 1 0 0 0 h`
1929 * - drag: Use Cell Motion Mouse Tracking `CSI ? 1 0 0 2 h`
1930 * - any: Use All Motion Mouse Tracking `CSI ? 1 0 0 3 h`
1931 */
1932 readonly mouseTrackingMode: 'none' | 'x10' | 'vt200' | 'drag' | 'any';
1933 /**
1934 * Origin Mode (DECOM): `CSI ? 6 h`
1935 */
1936 readonly originMode: boolean;
1937 /**
1938 * Reverse-wraparound Mode: `CSI ? 4 5 h`
1939 */
1940 readonly reverseWraparoundMode: boolean;
1941 /**
1942 * Send FocusIn/FocusOut events: `CSI ? 1 0 0 4 h`
1943 */
1944 readonly sendFocusMode: boolean;
1945 /**
1946 * Synchronized Output Mode: `CSI ? 2 0 2 6 h`
1947 *
1948 * When enabled, output is buffered and only rendered when the mode is
1949 * disabled, allowing for atomic screen updates without tearing.
1950 */
1951 readonly synchronizedOutputMode: boolean;
1952 /**
1953 * Auto-Wrap Mode (DECAWM): `CSI ? 7 h`
1954 */
1955 readonly wraparoundMode: boolean;
1956 }
1957 }