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.
10 /// <reference lib="dom"/>
12 declare module 'xterm' {
14 * A string representing text font weight.
16 export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
19 * A string representing log level.
21 export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'off';
24 * A string representing a renderer type.
26 export type RendererType = 'dom' | 'canvas';
29 * An object containing start up options for the terminal.
31 export interface ITerminalOptions {
33 * Whether background should support non-opaque color. It must be set before
34 * executing the `Terminal.open()` method and can't be changed later without
35 * executing it again. Note that enabling this can negatively impact
38 allowTransparency?: boolean;
41 * A data uri of the sound to use for the bell when `bellStyle = 'sound'`.
46 * The type of the bell notification the terminal will use.
48 bellStyle?: 'none' /*| 'visual'*/ | 'sound' /*| 'both'*/;
51 * When enabled the cursor will be set to the beginning of the next line
52 * with every new line. This equivalent to sending '\r\n' for each '\n'.
53 * Normally the termios settings of the underlying PTY deals with the
54 * translation of '\n' to '\r\n' and this setting should not be used. If you
55 * deal with data from a non-PTY related source, this settings might be
61 * The number of columns in the terminal.
66 * Whether the cursor blinks.
68 cursorBlink?: boolean;
71 * The style of the cursor.
73 cursorStyle?: 'block' | 'underline' | 'bar';
76 * Whether input should be disabled.
78 disableStdin?: boolean;
81 * Whether to draw bold text in bright colors. The default is true.
83 drawBoldTextInBrightColors?: boolean;
86 * The modifier key hold to multiply scroll speed.
88 fastScrollModifier?: 'alt' | 'ctrl' | 'shift' | undefined;
91 * The scroll speed multiplier used for fast scrolling.
93 fastScrollSensitivity?: number;
96 * The font size used to render text.
101 * The font family used to render text.
106 * The font weight used to render non-bold text.
108 fontWeight?: FontWeight;
111 * The font weight used to render bold text.
113 fontWeightBold?: FontWeight;
116 * The spacing in whole pixels between characters..
118 letterSpacing?: number;
121 * The line height used to render text.
126 * What log level to use, this will log for all levels below and including
138 * Whether to treat option as the meta key.
140 macOptionIsMeta?: boolean;
143 * Whether holding a modifier key will force normal selection behavior,
144 * regardless of whether the terminal is in mouse events mode. This will
145 * also prevent mouse events from being emitted by the terminal. For
146 * example, this allows you to use xterm.js' regular selection inside tmux
147 * with mouse mode enabled.
149 macOptionClickForcesSelection?: boolean;
152 * The type of renderer to use, this allows using the fallback DOM renderer
153 * when canvas is too slow for the environment. The following features do
154 * not work when the DOM renderer is used:
159 rendererType?: RendererType;
162 * Whether to select the word under the cursor on right click, this is
163 * standard behavior in a lot of macOS applications.
165 rightClickSelectsWord?: boolean;
168 * The number of rows in the terminal.
173 * Whether screen reader support is enabled. When on this will expose
174 * supporting elements in the DOM to support NVDA on Windows and VoiceOver
177 screenReaderMode?: boolean;
180 * The amount of scrollback in the terminal. Scrollback is the amount of
181 * rows that are retained when lines are scrolled beyond the initial
187 * The scrolling speed multiplier used for adjusting normal scrolling speed.
189 scrollSensitivity?: number;
192 * The size of tab stops in the terminal.
194 tabStopWidth?: number;
197 * The color theme of the terminal.
202 * Whether "Windows mode" is enabled. Because Windows backends winpty and
203 * conpty operate by doing line wrapping on their side, xterm.js does not
204 * have access to wrapped lines. When Windows mode is enabled the following
205 * changes will be in effect:
207 * - Reflow is disabled.
208 * - Lines are assumed to be wrapped if the last character of the line is
211 windowsMode?: boolean;
214 * A string containing all characters that are considered word separated by the
215 * double click to select work logic.
217 wordSeparator?: string;
221 * Contains colors to theme the terminal with.
223 export interface ITheme {
224 /** The default foreground color */
226 /** The default background color */
228 /** The cursor color */
230 /** The accent color of the cursor (fg color for a block cursor) */
231 cursorAccent?: string;
232 /** The selection background color (can be transparent) */
234 /** ANSI black (eg. `\x1b[30m`) */
236 /** ANSI red (eg. `\x1b[31m`) */
238 /** ANSI green (eg. `\x1b[32m`) */
240 /** ANSI yellow (eg. `\x1b[33m`) */
242 /** ANSI blue (eg. `\x1b[34m`) */
244 /** ANSI magenta (eg. `\x1b[35m`) */
246 /** ANSI cyan (eg. `\x1b[36m`) */
248 /** ANSI white (eg. `\x1b[37m`) */
250 /** ANSI bright black (eg. `\x1b[1;30m`) */
251 brightBlack?: string;
252 /** ANSI bright red (eg. `\x1b[1;31m`) */
254 /** ANSI bright green (eg. `\x1b[1;32m`) */
255 brightGreen?: string;
256 /** ANSI bright yellow (eg. `\x1b[1;33m`) */
257 brightYellow?: string;
258 /** ANSI bright blue (eg. `\x1b[1;34m`) */
260 /** ANSI bright magenta (eg. `\x1b[1;35m`) */
261 brightMagenta?: string;
262 /** ANSI bright cyan (eg. `\x1b[1;36m`) */
264 /** ANSI bright white (eg. `\x1b[1;37m`) */
265 brightWhite?: string;
269 * An object containing options for a link matcher.
271 export interface ILinkMatcherOptions {
273 * The index of the link from the regex.match(text) call. This defaults to 0
274 * (for regular expressions without capture groups).
279 * A callback that validates whether to create an individual link, pass
280 * whether the link is valid to the callback.
282 validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void;
285 * A callback that fires when the mouse hovers over a link for a moment.
287 tooltipCallback?: (event: MouseEvent, uri: string, location: IViewportRange) => boolean | void;
290 * A callback that fires when the mouse leaves a link. Note that this can
291 * happen even when tooltipCallback hasn't fired for the link yet.
293 leaveCallback?: () => void;
296 * The priority of the link matcher, this defines the order in which the
297 * link matcher is evaluated relative to others, from highest to lowest. The
298 * default value is 0.
303 * A callback that fires when the mousedown and click events occur that
304 * determines whether a link will be activated upon click. This enables
305 * only activating a link when a certain modifier is held down, if not the
306 * mouse event will continue propagation (eg. double click to select word).
308 willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
312 * An object that can be disposed via a dispose function.
314 export interface IDisposable {
319 * An event that can be listened to.
320 * @returns an `IDisposable` to stop listening.
322 export interface IEvent<T> {
323 (listener: (e: T) => any): IDisposable;
327 * Represents a specific line in the terminal that is tracked when scrollback
328 * is trimmed and lines are added or removed. This is a single line that may
329 * be part of a larger wrapped line.
331 export interface IMarker extends IDisposable {
333 * A unique identifier for this marker.
338 * Whether this marker is disposed.
340 readonly isDisposed: boolean;
343 * The actual line index in the buffer at this point in time. This is set to
344 * -1 if the marker has been disposed.
346 readonly line: number;
350 * The set of localizable strings.
352 export interface ILocalizableStrings {
354 * The aria label for the underlying input textarea for the terminal.
359 * Announcement for when line reading is suppressed due to too many lines
360 * being printed to the terminal when `screenReaderMode` is enabled.
362 tooMuchOutput: string;
366 * The class that represents an xterm.js terminal.
368 export class Terminal implements IDisposable {
370 * The element containing the terminal.
372 readonly element: HTMLElement | undefined;
375 * The textarea that accepts input for the terminal.
377 readonly textarea: HTMLTextAreaElement | undefined;
380 * The number of rows in the terminal's viewport. Use
381 * `ITerminalOptions.rows` to set this in the constructor and
382 * `Terminal.resize` for when the terminal exists.
384 readonly rows: number;
387 * The number of columns in the terminal's viewport. Use
388 * `ITerminalOptions.cols` to set this in the constructor and
389 * `Terminal.resize` for when the terminal exists.
391 readonly cols: number;
394 * (EXPERIMENTAL) The terminal's current buffer, this might be either the
395 * normal buffer or the alt buffer depending on what's running in the
398 readonly buffer: IBuffer;
401 * (EXPERIMENTAL) Get all markers registered against the buffer. If the alt
402 * buffer is active this will always return [].
404 readonly markers: ReadonlyArray<IMarker>;
407 * (EXPERIMENTAL) Get the parser interface to register
408 * custom escape sequence handlers.
410 readonly parser: IParser;
413 * Natural language strings that can be localized.
415 static strings: ILocalizableStrings;
418 * Creates a new `Terminal` object.
420 * @param options An object containing a set of options.
422 constructor(options?: ITerminalOptions);
425 * Adds an event listener for the cursor moves.
426 * @returns an `IDisposable` to stop listening.
428 onCursorMove: IEvent<void>;
431 * Adds an event listener for when a data event fires. This happens for
432 * example when the user types or pastes into the terminal. The event value
433 * is whatever `string` results, in a typical setup, this should be passed
434 * on to the backing pty.
435 * @returns an `IDisposable` to stop listening.
437 onData: IEvent<string>;
440 * Adds an event listener for a key is pressed. The event value contains the
441 * string that will be sent in the data event as well as the DOM event that
443 * @returns an `IDisposable` to stop listening.
445 onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
448 * Adds an event listener for when a line feed is added.
449 * @returns an `IDisposable` to stop listening.
451 onLineFeed: IEvent<void>;
454 * Adds an event listener for when a scroll occurs. The event value is the
455 * new position of the viewport.
456 * @returns an `IDisposable` to stop listening.
458 onScroll: IEvent<number>;
461 * Adds an event listener for when a selection change occurs.
462 * @returns an `IDisposable` to stop listening.
464 onSelectionChange: IEvent<void>;
467 * Adds an event listener for when rows are rendered. The event value
468 * contains the start row and end rows of the rendered area (ranges from `0`
469 * to `Terminal.rows - 1`).
470 * @returns an `IDisposable` to stop listening.
472 onRender: IEvent<{ start: number, end: number }>;
475 * Adds an event listener for when the terminal is resized. The event value
476 * contains the new size.
477 * @returns an `IDisposable` to stop listening.
479 onResize: IEvent<{ cols: number, rows: number }>;
482 * Adds an event listener for when an OSC 0 or OSC 2 title change occurs.
483 * The event value is the new title.
484 * @returns an `IDisposable` to stop listening.
486 onTitleChange: IEvent<string>;
489 * Unfocus the terminal.
494 * Focus the terminal.
499 * Resizes the terminal. It's best practice to debounce calls to resize,
500 * this will help ensure that the pty can respond to the resize event
501 * before another one occurs.
502 * @param x The number of columns to resize to.
503 * @param y The number of rows to resize to.
505 resize(columns: number, rows: number): void;
508 * Opens the terminal within an element.
509 * @param parent The element to create the terminal within. This element
510 * must be visible (have dimensions) when `open` is called as several DOM-
511 * based measurements need to be performed when this function is called.
513 open(parent: HTMLElement): void;
516 * Attaches a custom key event handler which is run before keys are
517 * processed, giving consumers of xterm.js ultimate control as to what keys
518 * should be processed by the terminal and what keys should not.
519 * @param customKeyEventHandler The custom KeyboardEvent handler to attach.
520 * This is a function that takes a KeyboardEvent, allowing consumers to stop
521 * propagation and/or prevent the default action. The function returns
522 * whether the event should be processed by xterm.js.
524 attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
527 * (EXPERIMENTAL) Registers a link matcher, allowing custom link patterns to
528 * be matched and handled.
529 * @param regex The regular expression to search for, specifically this
530 * searches the textContent of the rows. You will want to use \s to match a
531 * space ' ' character for example.
532 * @param handler The callback when the link is called.
533 * @param options Options for the link matcher.
534 * @return The ID of the new matcher, this can be used to deregister.
536 registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): number;
539 * (EXPERIMENTAL) Deregisters a link matcher if it has been registered.
540 * @param matcherId The link matcher's ID (returned after register)
542 deregisterLinkMatcher(matcherId: number): void;
545 * (EXPERIMENTAL) Registers a character joiner, allowing custom sequences of
546 * characters to be rendered as a single unit. This is useful in particular
547 * for rendering ligatures and graphemes, among other things.
549 * Each registered character joiner is called with a string of text
550 * representing a portion of a line in the terminal that can be rendered as
551 * a single unit. The joiner must return a sorted array, where each entry is
552 * itself an array of length two, containing the start (inclusive) and end
553 * (exclusive) index of a substring of the input that should be rendered as
554 * a single unit. When multiple joiners are provided, the results of each
555 * are collected. If there are any overlapping substrings between them, they
556 * are combined into one larger unit that is drawn together.
558 * All character joiners that are registered get called every time a line is
559 * rendered in the terminal, so it is essential for the handler function to
560 * run as quickly as possible to avoid slowdowns when rendering. Similarly,
561 * joiners should strive to return the smallest possible substrings to
562 * render together, since they aren't drawn as optimally as individual
565 * NOTE: character joiners are only used by the canvas renderer.
567 * @param handler The function that determines character joins. It is called
568 * with a string of text that is eligible for joining and returns an array
569 * where each entry is an array containing the start (inclusive) and end
570 * (exclusive) indexes of ranges that should be rendered as a single unit.
571 * @return The ID of the new joiner, this can be used to deregister
573 registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
576 * (EXPERIMENTAL) Deregisters the character joiner if one was registered.
577 * NOTE: character joiners are only used by the canvas renderer.
578 * @param joinerId The character joiner's ID (returned after register)
580 deregisterCharacterJoiner(joinerId: number): void;
583 * (EXPERIMENTAL) Adds a marker to the normal buffer and returns it. If the
584 * alt buffer is active, undefined is returned.
585 * @param cursorYOffset The y position offset of the marker from the cursor.
587 addMarker(cursorYOffset: number): IMarker;
590 * Gets whether the terminal has an active selection.
592 hasSelection(): boolean;
595 * Gets the terminal's current selection, this is useful for implementing
596 * copy behavior outside of xterm.js.
598 getSelection(): string;
601 * Gets the selection position or undefined if there is no selection.
603 getSelectionPosition(): ISelectionPosition | undefined;
606 * Clears the current terminal selection.
608 clearSelection(): void;
611 * Selects text within the terminal.
612 * @param column The column the selection starts at..
613 * @param row The row the selection starts at.
614 * @param length The length of the selection.
616 select(column: number, row: number, length: number): void;
619 * Selects all text within the terminal.
624 * Selects text in the buffer between 2 lines.
625 * @param start The 0-based line index to select from (inclusive).
626 * @param end The 0-based line index to select to (inclusive).
628 selectLines(start: number, end: number): void;
631 * Disposes of the terminal, detaching it from the DOM and removing any
637 * Scroll the display of the terminal
638 * @param amount The number of lines to scroll down (negative scroll up).
640 scrollLines(amount: number): void;
643 * Scroll the display of the terminal by a number of pages.
644 * @param pageCount The number of pages to scroll (negative scrolls up).
646 scrollPages(pageCount: number): void;
649 * Scrolls the display of the terminal to the top.
654 * Scrolls the display of the terminal to the bottom.
656 scrollToBottom(): void;
659 * Scrolls to a line within the buffer.
660 * @param line The 0-based line index to scroll to.
662 scrollToLine(line: number): void;
665 * Clear the entire buffer, making the prompt line the new first line.
670 * Write data to the terminal.
671 * @param data The data to write to the terminal. This can either be raw
672 * bytes given as Uint8Array from the pty or a string. Raw bytes will always
673 * be treated as UTF-8 encoded, string data as UTF-16.
674 * @param callback Optional callback that fires when the data was processed
677 write(data: string | Uint8Array, callback?: () => void): void;
680 * Writes data to the terminal, followed by a break line character (\n).
681 * @param data The data to write to the terminal. This can either be raw
682 * bytes given as Uint8Array from the pty or a string. Raw bytes will always
683 * be treated as UTF-8 encoded, string data as UTF-16.
684 * @param callback Optional callback that fires when the data was processed
687 writeln(data: string | Uint8Array, callback?: () => void): void;
690 * Write UTF8 data to the terminal.
691 * @param data The data to write to the terminal.
692 * @param callback Optional callback when data was processed.
693 * @deprecated use `write` instead
695 writeUtf8(data: Uint8Array, callback?: () => void): void;
698 * Writes text to the terminal, performing the necessary transformations for pasted text.
699 * @param data The text to write to the terminal.
701 paste(data: string): void;
704 * Retrieves an option's value from the terminal.
705 * @param key The option key.
707 getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'fontFamily' | 'fontWeight' | 'fontWeightBold' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string;
709 * Retrieves an option's value from the terminal.
710 * @param key The option key.
712 getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell' | 'windowsMode'): boolean;
714 * Retrieves an option's value from the terminal.
715 * @param key The option key.
717 getOption(key: 'colors'): string[];
719 * Retrieves an option's value from the terminal.
720 * @param key The option key.
722 getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number;
724 * Retrieves an option's value from the terminal.
725 * @param key The option key.
727 getOption(key: 'handler'): (data: string) => void;
729 * Retrieves an option's value from the terminal.
730 * @param key The option key.
732 getOption(key: string): any;
735 * Sets an option on the terminal.
736 * @param key The option key.
737 * @param value The option value.
739 setOption(key: 'fontFamily' | 'termName' | 'bellSound' | 'wordSeparator', value: string): void;
741 * Sets an option on the terminal.
742 * @param key The option key.
743 * @param value The option value.
745 setOption(key: 'fontWeight' | 'fontWeightBold', value: null | 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'): void;
747 * Sets an option on the terminal.
748 * @param key The option key.
749 * @param value The option value.
751 setOption(key: 'logLevel', value: LogLevel): void;
753 * Sets an option on the terminal.
754 * @param key The option key.
755 * @param value The option value.
757 setOption(key: 'bellStyle', value: null | 'none' | 'visual' | 'sound' | 'both'): void;
759 * Sets an option on the terminal.
760 * @param key The option key.
761 * @param value The option value.
763 setOption(key: 'cursorStyle', value: null | 'block' | 'underline' | 'bar'): void;
765 * Sets an option on the terminal.
766 * @param key The option key.
767 * @param value The option value.
769 setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'popOnBell' | 'rightClickSelectsWord' | 'screenKeys' | 'useFlowControl' | 'visualBell' | 'windowsMode', value: boolean): void;
771 * Sets an option on the terminal.
772 * @param key The option key.
773 * @param value The option value.
775 setOption(key: 'colors', value: string[]): void;
777 * Sets an option on the terminal.
778 * @param key The option key.
779 * @param value The option value.
781 setOption(key: 'fontSize' | 'letterSpacing' | 'lineHeight' | 'tabStopWidth' | 'scrollback', value: number): void;
783 * Sets an option on the terminal.
784 * @param key The option key.
785 * @param value The option value.
787 setOption(key: 'handler', value: (data: string) => void): void;
789 * Sets an option on the terminal.
790 * @param key The option key.
791 * @param value The option value.
793 setOption(key: 'theme', value: ITheme): void;
795 * Sets an option on the terminal.
796 * @param key The option key.
797 * @param value The option value.
799 setOption(key: 'cols' | 'rows', value: number): void;
801 * Sets an option on the terminal.
802 * @param key The option key.
803 * @param value The option value.
805 setOption(key: string, value: any): void;
808 * Tells the renderer to refresh terminal content between two rows
809 * (inclusive) at the next opportunity.
810 * @param start The row to start from (between 0 and this.rows - 1).
811 * @param end The row to end at (between start and this.rows - 1).
813 refresh(start: number, end: number): void;
816 * Perform a full reset (RIS, aka '\x1bc').
821 * Loads an addon into this instance of xterm.js.
822 * @param addon The addon to load.
824 loadAddon(addon: ITerminalAddon): void;
828 * An addon that can provide additional functionality to the terminal.
830 export interface ITerminalAddon extends IDisposable {
832 * This is called when the addon is activated.
834 activate(terminal: Terminal): void;
838 * An object representing a selection within the terminal.
840 interface ISelectionPosition {
842 * The start column of the selection.
847 * The start row of the selection.
852 * The end column of the selection.
857 * The end row of the selection.
863 * An object representing a range within the viewport of the terminal.
865 export interface IViewportRange {
867 * The start of the range.
869 start: IViewportRangePosition;
872 * The end of the range.
874 end: IViewportRangePosition;
878 * An object representing a cell position within the viewport of the terminal.
880 interface IViewportRangePosition {
882 * The x position of the cell. This is a 0-based index that refers to the
883 * space in between columns, not the column itself. Index 0 refers to the
884 * left side of the viewport, index `Terminal.cols` refers to the right side
885 * of the viewport. This can be thought of as how a cursor is positioned in
891 * The y position of the cell. This is a 0-based index that refers to a
898 * Represents a terminal buffer.
902 * The y position of the cursor. This ranges between `0` (when the
903 * cursor is at baseY) and `Terminal.rows - 1` (when the cursor is on the
906 readonly cursorY: number;
909 * The x position of the cursor. This ranges between `0` (left side) and
910 * `Terminal.cols - 1` (right side).
912 readonly cursorX: number;
915 * The line within the buffer where the top of the viewport is.
917 readonly viewportY: number;
920 * The line within the buffer where the top of the bottom page is (when
921 * fully scrolled down);
923 readonly baseY: number;
926 * The amount of lines in the buffer.
928 readonly length: number;
931 * Gets a line from the buffer, or undefined if the line index does not
934 * Note that the result of this function should be used immediately after
935 * calling as when the terminal updates it could lead to unexpected
938 * @param y The line index to get.
940 getLine(y: number): IBufferLine | undefined;
944 * Represents a line in the terminal's buffer.
946 interface IBufferLine {
948 * Whether the line is wrapped from the previous line.
950 readonly isWrapped: boolean;
953 * Gets a cell from the line, or undefined if the line index does not exist.
955 * Note that the result of this function should be used immediately after
956 * calling as when the terminal updates it could lead to unexpected
959 * @param x The character index to get.
961 getCell(x: number): IBufferCell | undefined;
964 * Gets the line as a string. Note that this is gets only the string for the
965 * line, not taking isWrapped into account.
967 * @param trimRight Whether to trim any whitespace at the right of the line.
968 * @param startColumn The column to start from (inclusive).
969 * @param endColumn The column to end at (exclusive).
971 translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
975 * Represents a single cell in the terminal's buffer.
977 interface IBufferCell {
979 * The character within the cell.
981 readonly char: string;
984 * The width of the character. Some examples:
986 * - This is `1` for most cells.
987 * - This is `2` for wide character like CJK glyphs.
988 * - This is `0` for cells immediately following cells with a width of `2`.
990 readonly width: number;
994 * (EXPERIMENTAL) Data type to register a CSI, DCS or ESC callback in the parser
997 * CSI Prefix P..P I..I F
998 * DCS Prefix P..P I..I F data_bytes ST
1000 * with these rules/restrictions:
1001 * - prefix can only be used with CSI and DCS
1002 * - only one leading prefix byte is recognized by the parser
1003 * before any other parameter bytes (P..P)
1004 * - intermediate bytes are recognized up to 2
1006 * For custom sequences make sure to read ECMA-48 and the resources at
1007 * vt100.net to not clash with existing sequences or reserved address space.
1008 * General recommendations:
1009 * - use private address space (see ECMA-48)
1010 * - use max one intermediate byte (technically not limited by the spec,
1011 * in practice there are no sequences with more than one intermediate byte,
1012 * thus parsers might get confused with more intermediates)
1013 * - test against other common emulators to check whether they escape/ignore
1014 * the sequence correctly
1016 * Notes: OSC command registration is handled differently (see addOscHandler)
1017 * APC, PM or SOS is currently not supported.
1019 export interface IFunctionIdentifier {
1021 * Optional prefix byte, must be in range \x3c .. \x3f.
1022 * Usable in CSI and DCS.
1026 * Optional intermediate bytes, must be in range \x20 .. \x2f.
1027 * Usable in CSI, DCS and ESC.
1029 intermediates?: string;
1031 * Final byte, must be in range \x40 .. \x7e for CSI and DCS,
1032 * \x30 .. \x7e for ESC.
1038 * (EXPERIMENTAL) Parser interface.
1040 export interface IParser {
1042 * Adds a handler for CSI escape sequences.
1043 * @param id Specifies the function identifier under which the callback
1044 * gets registered, e.g. {final: 'm'} for SGR.
1045 * @param callback The function to handle the sequence. The callback is
1046 * called with the numerical params. If the sequence has subparams the
1047 * array will contain subarrays with their numercial values.
1048 * Return true if the sequence was handled; false if we should try
1049 * a previous handler (set by addCsiHandler or setCsiHandler).
1050 * The most recently-added handler is tried first.
1051 * @return An IDisposable you can call to remove this handler.
1053 addCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean): IDisposable;
1056 * Adds a handler for DCS escape sequences.
1057 * @param id Specifies the function identifier under which the callback
1058 * gets registered, e.g. {intermediates: '$' final: 'q'} for DECRQSS.
1059 * @param callback The function to handle the sequence. Note that the
1060 * function will only be called once if the sequence finished sucessfully.
1061 * There is currently no way to intercept smaller data chunks, data chunks
1062 * will be stored up until the sequence is finished. Since DCS sequences
1063 * are not limited by the amount of data this might impose a problem for
1064 * big payloads. Currently xterm.js limits DCS payload to 10 MB
1065 * which should give enough room for most use cases.
1066 * The function gets the payload and numerical parameters as arguments.
1067 * Return true if the sequence was handled; false if we should try
1068 * a previous handler (set by addDcsHandler or setDcsHandler).
1069 * The most recently-added handler is tried first.
1070 * @return An IDisposable you can call to remove this handler.
1072 addDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean): IDisposable;
1075 * Adds a handler for ESC escape sequences.
1076 * @param id Specifies the function identifier under which the callback
1077 * gets registered, e.g. {intermediates: '%' final: 'G'} for
1078 * default charset selection.
1079 * @param callback The function to handle the sequence.
1080 * Return true if the sequence was handled; false if we should try
1081 * a previous handler (set by addEscHandler or setEscHandler).
1082 * The most recently-added handler is tried first.
1083 * @return An IDisposable you can call to remove this handler.
1085 addEscHandler(id: IFunctionIdentifier, handler: () => boolean): IDisposable;
1088 * Adds a handler for OSC escape sequences.
1089 * @param ident The number (first parameter) of the sequence.
1090 * @param callback The function to handle the sequence. Note that the
1091 * function will only be called once if the sequence finished sucessfully.
1092 * There is currently no way to intercept smaller data chunks, data chunks
1093 * will be stored up until the sequence is finished. Since OSC sequences
1094 * are not limited by the amount of data this might impose a problem for
1095 * big payloads. Currently xterm.js limits OSC payload to 10 MB
1096 * which should give enough room for most use cases.
1097 * The callback is called with OSC data string.
1098 * Return true if the sequence was handled; false if we should try
1099 * a previous handler (set by addOscHandler or setOscHandler).
1100 * The most recently-added handler is tried first.
1101 * @return An IDisposable you can call to remove this handler.
1103 addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable;