UNPKG

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