### Install xterm.js with npm or Yarn Source: https://xtermjs.org/docs/guides/download Use npm or Yarn to install xterm.js for your project. These are the recommended methods for obtaining the library. ```bash npm install @xterm/xterm ``` ```bash yarn add @xterm/xterm ``` -------------------------------- ### Create a Custom DataLoggerAddon Source: https://xtermjs.org/docs/guides/using-addons Implement a custom addon by exporting an object with 'activate' and 'dispose' methods. This example logs all data events from the terminal. ```typescript import { Terminal, IDisposable } from '@xterm/xterm'; class DataLoggerAddon { private _disposables: IDisposable[] = []; activate(terminal: Terminal): void { this._disposables.push(terminal.onData(d => console.log(d))); } dispose(): void { this._disposables.forEach(d => d.dispose()); this._disposables.length = 0; } } ``` -------------------------------- ### Spawning Shell with luit for Encoding Source: https://xtermjs.org/docs/guides/encoding Wraps the shell command with 'luit' to handle specific encodings before spawning the PTY. 'luit' must be installed separately. ```javascript const pty = node_pty.spawn(shell, [], {...}); ``` ```javascript const pty = node_pty.spawn('luit', ['-encoding', 'ENCODING', '', '--', shell], {...}); ``` -------------------------------- ### Clone xterm.js repository and build Source: https://xtermjs.org/docs/guides/download Clone the xterm.js repository from GitHub, install dependencies, and build the project. This method is not suggested for production usage. ```bash git clone https://github.com/xtermjs/xterm.js cd xterm.js npm install npm run build ``` -------------------------------- ### Custom CSI Handler for Window Options Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Implement custom handling for CSI 't' sequences to manage window options. This example shows how to add a handler for 't' and process different parameter values. ```typescript term.parser.addCsiHandler({final: 't'}, params => { const ps = params[0]; switch (ps) { case XY: ... // your implementation for option XY return true; // signal Ps=XY was handled } return false; // any Ps that was not handled }); ``` -------------------------------- ### options Property Source: https://xtermjs.org/docs/api/terminal/classes/terminal Gets or sets the terminal options. Supports setting multiple options at once. When setting object-valued options like 'theme', a new object must be provided for changes to take effect. ```APIDOC ## options ### Description Gets or sets the terminal options. This supports setting multiple options. ### Example Get a single option: ``` console.log(terminal.options.fontSize); ``` Set a single option: ``` terminal.options.fontSize = 12; ``` Note that for options that are objects, a new object must be used in order to take effect as a reference comparison will be done: ``` const newValue = terminal.options.theme; newValue.background = '#000000'; // This won't work terminal.options.theme = newValue; // This will work terminal.options.theme = { ...newValue }; ``` Set multiple options: ``` terminal.options = { fontSize: 12, fontFamily: 'Courier New' }; ``` ### Type ITerminalOptions ``` -------------------------------- ### ITerminalInitOnlyOptions Source: https://xtermjs.org/docs/api/terminal/interfaces/iterminalinitonlyoptions An object containing additional options for the terminal that can only be set on start up. ```APIDOC ## Interface: ITerminalInitOnlyOptions An object containing additional options for the terminal that can only be set on start up. ### Properties #### Optional `cols` - **cols**? : _number_ The number of columns in the terminal. #### Optional `rows` - **rows**? : _number_ The number of rows in the terminal. ``` -------------------------------- ### Setup Link Handling in xterm.js Source: https://xtermjs.org/docs/guides/link-handling Configure a link handler for both explicit OSC 8 links and implicitly detected URLs. The `activateLink` function is called when a link is clicked, and the `linkHandler` object defines callbacks for activation, hover, and leave events. Setting `allowNonHttpProtocols` to true permits custom protocols. ```javascript function activateLink(event, uri) { doHandleLink(); // example: open link in new browser window } let linkHandler = { activate: (event, text, range) => { activateLink(event, text); } , hover: (event, text, range) => { /* nothing, by default */}, leave: (event, text, range) => { /* nothing, by default */}, allowNonHttpProtocols: true }; /* Detect links because of URL patterns. */ webLinksAddon = new WebLinksAddon(activateLink, linkHandler); /* Handle explicit links using USC 8 escape sequences. */ xterm.options.linkHandler = linkHandler; ``` -------------------------------- ### Basic node-pty Integration with xterm.js Source: https://xtermjs.org/docs/guides/encoding Standard setup for piping data between a PTY process and an xterm.js terminal. Assumes UTF-8 encoding by default. ```javascript pty.onData(recv => terminal.write(recv)); terminal.onData(send => pty.write(send)); ``` -------------------------------- ### getSelectionPosition Source: https://xtermjs.org/docs/api/terminal/classes/terminal Gets the start and end position of the current selection, or undefined if no selection exists. ```APIDOC ## getSelectionPosition ### Description Gets the selection position or undefined if there is no selection. ### Method getSelectionPosition ### Returns IBufferRange | undefined ``` -------------------------------- ### Load a Custom Addon Source: https://xtermjs.org/docs/guides/using-addons Instantiate and load your custom addon using Terminal.loadAddon. Ensure the custom addon class is defined before this step. ```typescript const terminal = new Terminal(); terminal.loadAddon(new ExampleAddon()); ``` -------------------------------- ### Import xterm.js and Initialize Terminal Source: https://xtermjs.org/docs/guides/import Import the Terminal class from '@xterm/xterm' and initialize a new terminal instance. Ensure the CSS stylesheet is imported separately. ```javascript import { Terminal } from '@xterm/xterm'; const term = new Terminal(); term.open(document.getElementById('xterm-container')); ``` -------------------------------- ### IBufferRange Interface Source: https://xtermjs.org/docs/api/terminal/interfaces/ibufferrange Represents a range within a buffer, defined by start and end positions. ```APIDOC ## Interface: IBufferRange A range within a buffer. ### Properties - **start**: IBufferCellPosition - The start position of the range. - **end**: IBufferCellPosition - The end position of the range. ``` -------------------------------- ### Basic C "Hello World" Output Source: https://xtermjs.org/docs/guides/encoding This C code snippet demonstrates a simple console output. It is expected to print correctly across most systems due to its basic ASCII characters. ```c #include int main(void) { printf("Hello World!\n"); return 0; } ``` -------------------------------- ### Get Terminal Font Size Source: https://xtermjs.org/docs/api/terminal/classes/terminal Retrieve the current font size of the terminal. This is a read-only property. ```typescript console.log(terminal.options.fontSize); ``` -------------------------------- ### Load and Use FitAddon Source: https://xtermjs.org/docs/guides/using-addons Import and load the FitAddon to make the terminal's size and geometry fit its container. Ensure the container element exists in the DOM. ```typescript import { Terminal } from '@xterm/xterm'; import { FitAddon } from '@xterm/addon-fit'; const term = new Terminal(); const fitAddon = new FitAddon(); term.loadAddon(fitAddon); // Open the terminal in #terminal-container term.open(document.getElementById('terminal-container')); // Make the terminal's size and geometry fit the size of #terminal-container fitAddon.fit(); ``` -------------------------------- ### IViewportRange Interface Source: https://xtermjs.org/docs/api/terminal/interfaces/iviewportrange Represents a range within the viewport of the terminal. It has a start and an end property, both of type IViewportRangePosition. ```APIDOC ## Interface: IViewportRange An object representing a range within the viewport of the terminal. ### Properties * **start** : _IViewportRangePosition_ The start of the range. * **end** : _IViewportRangePosition_ The end of the range. ``` -------------------------------- ### loadAddon Source: https://xtermjs.org/docs/api/terminal/classes/terminal Loads an addon into the terminal instance, extending its functionality. ```APIDOC ## loadAddon ### Description Loads an addon into this instance of xterm.js. ### Method loadAddon ### Parameters #### Path Parameters - **addon** (ITerminalAddon) - Required - The addon to load. ### Returns void ``` -------------------------------- ### provideLinks Method Source: https://xtermjs.org/docs/api/terminal/interfaces/ilinkprovider Provides links for a given buffer line number. The callback is invoked with an array of ILink objects or undefined if no links are found. ```APIDOC ## provideLinks ### Description Provides a link a buffer position. ### Method provideLinks ### Parameters #### Path Parameters - **bufferLineNumber** (number) - Required - The y position of the buffer to check for links within. - **callback** (function) - Required - The callback to be fired when ready with the resulting link(s) for the line or `undefined`. - **links** (ILink[] | undefined) - Description of the links parameter for the callback. ### Returns - void ``` -------------------------------- ### Checking System Locale Settings Source: https://xtermjs.org/docs/guides/encoding Verify your system's locale configuration to ensure UTF-8 support. Pay close attention to LC_CTYPE and LC_ALL for correct character handling. ```bash $> locale LANG=de_DE.UTF-8 LANGUAGE=de_DE LC_CTYPE="de_DE.UTF-8" LC_NUMERIC="de_DE.UTF-8" LC_TIME="de_DE.UTF-8" LC_COLLATE="de_DE.UTF-8" LC_MONETARY="de_DE.UTF-8" LC_MESSAGES="de_DE.UTF-8" LC_PAPER="de_DE.UTF-8" LC_NAME="de_DE.UTF-8" LC_ADDRESS="de_DE.UTF-8" LC_TELEPHONE="de_DE.UTF-8" LC_MEASUREMENT="de_DE.UTF-8" LC_IDENTIFICATION="de_DE.UTF-8" LC_ALL= ``` -------------------------------- ### luit for Legacy Encoding Translation Source: https://xtermjs.org/docs/guides/encoding Use luit to transcode between foreign encodings and UTF-8 for terminal data streams. This example shows luit used for a single program. ```bash $> luit -encoding ISO8859-1 -- command ``` -------------------------------- ### open Source: https://xtermjs.org/docs/api/terminal/classes/terminal Opens the terminal within a specified HTML element, making it visible and ready for interaction. ```APIDOC ## open ### Description Opens the terminal within an element. This should also be called if the xterm.js element ever changes browser window. ### Method open ### Parameters #### Path Parameters - **parent** (HTMLElement) - Required - The element to create the terminal within. This element must be visible (have dimensions) when `open` is called as several DOM-based measurements need to be performed when this function is called. ### Returns void ``` -------------------------------- ### luit for SSH Transcoding Source: https://xtermjs.org/docs/guides/encoding Demonstrates using luit to transcode an SSH connection, adapting it to a specific locale for compatibility with legacy systems. ```bash $> LC_ALL=fr_FR luit ssh legacy-machine ``` -------------------------------- ### Registering and Chaining CSI Handlers in xterm.js Source: https://xtermjs.org/docs/guides/hooks Demonstrates how to register multiple CSI handlers and how they are invoked in reverse order of registration. Returning true from a handler stops further processing. ```javascript const term = new Terminal(); // after startup we have one default CUP handler term.write(`\x1b[H`); // write CUP(1, 1): --> default // register second CUP handler const customCUP = term.parser.registerCsiHandler({final: 'H'}, params => {...}); term.write(`\x1b[H`); // write CUP(1, 1): --> customCUP --> default // register third CUP handler const anotherCUP = term.parser.registerCsiHandler({final: 'H'}, params => {...}); term.write(`\x1b[H`); // write CUP(1, 1): --> anotherCUP --> customCUP --> default // register CUP handler, that stops further processing const stopCUP = term.parser.registerCsiHandler({final: 'H'}, params => { ...; return true; }); term.write(`\x1b[H`); // write CUP(1, 1): --> stopCUP ``` -------------------------------- ### Send Custom DCS Sequence for MIDI Source: https://xtermjs.org/docs/guides/hooks Send a custom DCS sequence to xterm.js to play MIDI data with a specified pitch. The first example sends a sequence with a custom pitch, while the second uses the default pitch of 440 Hz. ```javascript process.stdout.write(`\x1bP?${pitch}a${binaryMidiData.toString('base64')}\x1b\\`); ``` ```javascript process.stdout.write(`\x1bP?a${binaryMidiData.toString('base64')}\x1b\\`); // default pitch of 440 Hz ``` -------------------------------- ### IWindowsPty Properties Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowspty This snippet details the properties available on the IWindowsPty interface. ```APIDOC ## Interface: IWindowsPty Pty information for Windows. ### Properties #### backend - **Type**: "conpty" | "winpty" - **Optional**: true - **Description**: What pty emulation backend is being used. #### buildNumber - **Type**: number - **Optional**: true - **Description**: The Windows build version (eg. 19045) ``` -------------------------------- ### Register DCS Handler for MIDI Data Source: https://xtermjs.org/docs/guides/hooks Register a handler for a custom DCS sequence to process MIDI data. This example uses a DCS sequence with identifier '{prefix: '?', final: 'a'}' to accept a pitch parameter and BASE64 encoded MIDI payload. Always sanitize incoming data as it may be malicious. ```typescript const midiHandler = term.registerDcsHandler({prefix: '?', final: 'a'}, (params, data) => { // since params are optional, we have to provide some sane default // default: pitch to 440 Hz const pitch = params[0] || 440; // convert BASE64 string back to your midi format const midiData = convertB64ToMidi(data); // sanity checks (never skip that step, as the data might be malicious) if (isValidData(midiData)) { // some midi player you wrote before midiPlayer.play(pitch, midiData); } }); ``` -------------------------------- ### raiseWin Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Raises the terminal window to the top of the stacking order. Ps=5. No default implementation. ```APIDOC ## raiseWin ### Description Raises the terminal window to the top of the window stacking order. ### Parameters - **raiseWin** (boolean) - Optional - Set to true to raise the window. ### Note No default implementation is provided. ``` -------------------------------- ### activate Source: https://xtermjs.org/docs/api/terminal/interfaces/iterminaladdon This method is called when the addon is activated and integrated with the terminal instance. ```APIDOC ## activate ### Description This is called when the addon is activated. ### Method activate ### Parameters #### Path Parameters - **terminal** (Terminal) - Required - The terminal instance to activate the addon with. ### Returns - void ``` -------------------------------- ### getWinState Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Reports the terminal window state. Returns "CSI 1 t" if non-iconified, "CSI 2 t" if iconified. No default implementation. ```APIDOC ## getWinState ### Description Reports the current state of the terminal window (iconified or not). ### Parameters - **getWinState** (boolean) - Optional - Set to true to request the window state. ### Response - **Success Response (200)**: The terminal will respond with `CSI 1 t` if the window is not iconified, or `CSI 2 t` if it is iconified. ``` -------------------------------- ### minimizeWin Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Minimizes (iconifies) the terminal window. Ps=2. No default implementation. ```APIDOC ## minimizeWin ### Description Minimizes the terminal window to an icon. ### Parameters - **minimizeWin** (boolean) - Optional - Set to true to minimize the window. ### Note No default implementation is provided. ``` -------------------------------- ### selectAll Source: https://xtermjs.org/docs/api/terminal/classes/terminal Selects all text currently present in the terminal. ```APIDOC ## selectAll ### Description Selects all text within the terminal. ### Method selectAll ### Returns - void ``` -------------------------------- ### maximizeWin Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Maximizes the terminal window. Ps=9 ; 0 to restore, Ps=9 ; 1 to maximize, Ps=9 ; 2 to maximize vertically, Ps=9 ; 3 to maximize horizontally. No default implementation. ```APIDOC ## maximizeWin ### Description Maximizes the terminal window to different states (full screen, vertical, horizontal). ### Parameters - **maximizeWin** (boolean) - Optional - Controls the maximization state. - `0`: Restore maximized window. - `1`: Maximize window to screen size. - `2`: Maximize window vertically. - `3`: Maximize window horizontally. ### Note No default implementation is provided. ``` -------------------------------- ### lowerWin Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Lowers the terminal window to the bottom of the stacking order. Ps=6. No default implementation. ```APIDOC ## lowerWin ### Description Lowers the terminal window to the bottom of the window stacking order. ### Parameters - **lowerWin** (boolean) - Optional - Set to true to lower the window. ### Note No default implementation is provided. ``` -------------------------------- ### getWinSizePixels Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Reports the size of the text area in pixels. Ps=14 reports text area size, Ps=14 ; 2 reports window size. Result is "CSI 4 ; height ; width t". Has a default implementation. ```APIDOC ## getWinSizePixels ### Description Reports the dimensions of the terminal's text area or window in pixels (height and width). ### Parameters - **getWinSizePixels** (boolean) - Optional - Set to true to request the text area size in pixels. Use `14;2` to request the window size in pixels. ### Response - **Success Response (200)**: The terminal will respond with a CSI sequence containing the height and width in pixels. ``` -------------------------------- ### Terminal Constructor Source: https://xtermjs.org/docs/api/terminal/classes/terminal Creates a new Terminal object with optional initialization options. ```APIDOC ## new Terminal(options?) ### Description Creates a new `Terminal` object. ### Parameters - **options?** (ITerminalOptions & ITerminalInitOnlyOptions) - Optional - An object containing a set of options for terminal initialization. ``` -------------------------------- ### IBuffer Methods Source: https://xtermjs.org/docs/api/terminal/interfaces/ibuffer These are the methods available on the IBuffer interface for interacting with the terminal buffer. ```APIDOC ## IBuffer Methods ### getLine - **Signature**: `getLine(y: number): IBufferLine | undefined` - **Description**: Gets a line from the buffer, or undefined if the line index does not exist. Note that the result of this function should be used immediately after calling as when the terminal updates it could lead to unexpected behavior. - **Parameters**: - `y` (number): The line index to get. - **Returns**: `IBufferLine | undefined` ### getNullCell - **Signature**: `getNullCell(): IBufferCell` - **Description**: Creates an empty cell object suitable as a cell reference in `line.getCell(x, cell)`. Use this to avoid costly recreation of cell objects when dealing with tons of cells. - **Returns**: `IBufferCell` ``` -------------------------------- ### fullscreenWin Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Controls full-screen mode for the terminal window. Ps=10 ; 0 to undo, Ps=10 ; 1 to enter, Ps=10 ; 2 to toggle. No default implementation. ```APIDOC ## fullscreenWin ### Description Enable or disable full-screen mode for the terminal window. ### Parameters - **fullscreenWin** (boolean) - Optional - Controls the full-screen state. - `0`: Undo full-screen mode. - `1`: Change to full-screen. - `2`: Toggle full-screen. ### Note No default implementation is provided. ``` -------------------------------- ### raiseWin Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Raises the window to the front of the stacking order. This option is a boolean and has no default implementation. ```APIDOC ## raiseWin ### Description Raises the window to the front of the stacking order. ### Type boolean ### Defined in xterm.d.ts:709 ``` -------------------------------- ### restoreWin Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Restores a previously minimized or maximized terminal window. No default implementation. ```APIDOC ## restoreWin ### Description Restores the terminal window to its previous size and position, typically after being minimized or maximized. ### Parameters - **restoreWin** (boolean) - Optional - Set to true to restore the window. ### Note No default implementation is provided. ``` -------------------------------- ### Windows Pty Option Source: https://xtermjs.org/docs/api/terminal/interfaces/iterminaloptions Provides compatibility information when the PTY is hosted on Windows. Setting this enables specific heuristics and workarounds. ```APIDOC ## `Optional` windowsPty ### Description Compatibility information when the pty is known to be hosted on Windows. Setting this will turn on certain heuristics/workarounds depending on the values: * `if (backend !== undefined || buildNumber !== undefined)` * When increasing the rows in the terminal, the amount increased into the scrollback. This is done because ConPTY does not behave like expect scrollback to come back into the viewport, instead it makes empty rows at of the viewport. Not having this behavior can result in missing data as the rows get replaced. * `if !(backend === 'conpty' && buildNumber >= 21376)` * Reflow is disabled * Lines are assumed to be wrapped if the last character of the line is not whitespace. ### Type IWindowsPty ``` -------------------------------- ### getScreenSizePixels Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Reports the size of the screen in pixels. The result is "CSI 5 ; height ; width t". No default implementation. ```APIDOC ## getScreenSizePixels ### Description Reports the dimensions of the terminal screen in pixels (height and width). ### Parameters - **getScreenSizePixels** (boolean) - Optional - Set to true to request the screen size in pixels. ### Response - **Success Response (200)**: The terminal will respond with a CSI sequence containing the screen height and width in pixels. ``` -------------------------------- ### setWinSizePixels Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Resizes the window to a given height and width in pixels. Omitted or zero parameters reuse current dimensions or use the display's dimensions, respectively. This option is a boolean and has no default implementation. ```APIDOC ## setWinSizePixels ### Description Resize the window to given `height` and `width` in pixels. Omitted parameters should reuse the current height or width. Zero parameters should use the display’s height or width. ### Type boolean ### Defined in xterm.d.ts:704 ``` -------------------------------- ### Using iconv for Chunk-Level Encoding Conversion Source: https://xtermjs.org/docs/guides/encoding Employs the 'iconv' package to convert data between different encodings on a per-chunk basis. Requires manual handling of multi-byte sequences for some encodings. ```javascript const Iconv = require('iconv').Iconv; const receiveConverter = new Iconv('ISO-8859-1', 'UTF-8'); const sendConverter = new Iconv('UTF-8', 'ISO-8859-1'); ``` ```javascript const pty = node_pty.spawn(shell, {encoding=null, ...}); pty.onData(recv => terminal.write(receiveConverter.convert(recv))); terminal.onData(send => pty.write(sendConverter.convert(send))); ``` -------------------------------- ### setWinSizePixels Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Sets the size of the terminal window in pixels. Ps=15 ; height ; width. No default implementation. ```APIDOC ## setWinSizePixels ### Description Sets the size of the terminal window in pixels (height and width). ### Parameters - **setWinSizePixels** (object) - Optional - An object containing the height and width in pixels. - **height** (number) - The desired height in pixels. - **width** (number) - The desired width in pixels. ### Note No default implementation is provided. ``` -------------------------------- ### Terminal Options Source: https://xtermjs.org/docs/api/terminal/interfaces/iterminaloptions These are optional properties that can be passed to the Terminal constructor to configure its behavior and appearance. ```APIDOC ## Terminal Options ### `ignoreBracketedPasteMode` * **Type**: `boolean` * **Description**: Whether to ignore the bracketed paste mode. When true, this will always paste without the `\x1b[200~` and `\x1b[201~` sequences, even when the shell enables bracketed mode. ### `letterSpacing` * **Type**: `number` * **Description**: The spacing in whole pixels between characters. ### `lineHeight` * **Type**: `number` * **Description**: The line height used to render text. ### `linkHandler` * **Type**: `ILinkHandler | null` * **Description**: The handler for OSC 8 hyperlinks. Links will use the `confirm` browser API with a strongly worded warning if no link handler is set. When setting this, consider the security of users opening these links, at a minimum there should be a tooltip or a prompt when hovering or activating the link respectively. An example of what might be possible is a terminal app writing link in the form `javascript:...` that runs some javascript, a safe approach to prevent that is to validate the link starts with http(s)://. ### `logLevel` * **Type**: `LogLevel` * **Description**: What log level to use, this will log for all levels below and including what is set: 1. trace 2. debug 3. info (default) 4. warn 5. error 6. off ### `logger` * **Type**: `ILogger | null` * **Description**: A logger to use instead of `console`. ### `macOptionClickForcesSelection` * **Type**: `boolean` * **Description**: Whether holding a modifier key will force normal selection behavior, regardless of whether the terminal is in mouse events mode. This will also prevent mouse events from being emitted by the terminal. For example, this allows you to use xterm.js’ regular selection inside tmux with mouse mode enabled. ### `macOptionIsMeta` * **Type**: `boolean` * **Description**: Whether to treat option as the meta key. ### `minimumContrastRatio` * **Type**: `number` * **Description**: The minimum contrast ratio for text in the terminal, setting this will change the foreground color dynamically depending on whether the contrast ratio is met. Example values: * 1: The default, do nothing. * 4.5: Minimum for WCAG AA compliance. * 7: Minimum for WCAG AAA compliance. * 21: White on black or black on white. ### `overviewRuler` * **Type**: `IOverviewRulerOptions` * **Description**: Controls the visibility and style of the overview ruler which visualizes decorations underneath the scroll bar. ### `reflowCursorLine` * **Type**: `boolean` * **Description**: Whether to reflow the line containing the cursor when the terminal is resized. Defaults to false, because shells usually handle this themselves. ### `rescaleOverlappingGlyphs` * **Type**: `boolean` * **Description**: Whether to rescale glyphs horizontally that are a single cell wide but have glyphs that would overlap following cell(s). This typically happens for ambiguous width characters (eg. the roman numeral characters U+2160+) which aren’t featured in monospace fonts. This is an important feature for achieving GB18030 compliance. The following glyphs will never be rescaled: * Emoji glyphs * Powerline glyphs * Nerd font glyphs Note that this doesn’t work with the DOM renderer. The default is false. ### `rightClickSelectsWord` * **Type**: `boolean` * **Description**: Whether to select the word under the cursor on right click, this is standard behavior in a lot of macOS applications. ### `screenReaderMode` * **Type**: `boolean` * **Description**: Whether screen reader support is enabled. When on this will expose supporting elements in the DOM to support NVDA on Windows and VoiceOver on macOS. ### `scrollOnEraseInDisplay` * **Type**: `boolean` * **Description**: If enabled the Erase in Display All (ED2) escape sequence will push erased text to scrollback, instead of clearing only the viewport portion. This emulates PuTTY’s default clear screen behavior. ### `scrollOnUserInput` * **Type**: `boolean` * **Description**: Whether to scroll to the bottom whenever there is some user input. The default is true. ### `scrollSensitivity` * **Type**: `number` * **Description**: The scrolling speed multiplier used for adjusting normal scrolling speed. ``` -------------------------------- ### select Source: https://xtermjs.org/docs/api/terminal/classes/terminal Selects a range of text within the terminal based on column, row, and length. ```APIDOC ## select ### Description Selects text within the terminal. ### Method select ### Parameters #### Path Parameters - **column** (number) - Required - The column the selection starts at. - **row** (number) - Required - The row the selection starts at. - **length** (number) - Required - The length of the selection. ### Returns - void ``` -------------------------------- ### refreshWin Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Refreshes the terminal window. No default implementation. ```APIDOC ## refreshWin ### Description Refreshes the terminal window. This can be used to ensure the display is up-to-date. ### Parameters - **refreshWin** (boolean) - Optional - Set to true to trigger a refresh. ### Note No default implementation is provided. ``` -------------------------------- ### setWinLines Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Resizes the terminal to a specified number of lines (Ps). This setting is also used to enable/disable DECCOLM. DECSLPP is not implemented. ```APIDOC ## setWinLines ### Description Resize to Ps lines (DECSLPP). DECSLPP is not implemented. This settings is also used to enable / disable DECCOLM (earlier variant of DECSLPP). ### Type boolean ### Defined in xterm.d.ts:807 ``` -------------------------------- ### setWinLines Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Sets the number of lines in the terminal window. No default implementation. ```APIDOC ## setWinLines ### Description Sets the number of lines (height) for the terminal window. ### Parameters - **setWinLines** (number) - Optional - The desired number of lines for the terminal window. ### Note No default implementation is provided. ``` -------------------------------- ### restoreWin Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions De-iconifies the window. This option is a boolean and has no default implementation. ```APIDOC ## restoreWin ### Description De-iconify window. ### Type boolean ### Defined in xterm.d.ts:685 ``` -------------------------------- ### Terminal Methods Source: https://xtermjs.org/docs/api/terminal/classes/terminal Core methods for interacting with the Terminal, including input, output, selection, and lifecycle management. ```APIDOC ## Terminal Methods ### attachCustomKeyEventHandler - **attachCustomKeyEventHandler**(handler: (event: KeyboardEvent) => void): void - Attaches a custom key event handler. ### attachCustomWheelEventHandler - **attachCustomWheelEventHandler**(handler: (event: WheelEvent) => void): void - Attaches a custom wheel event handler. ### blur - **blur**(): void - Removes focus from the terminal. ### clear - **clear**(): void - Clears the terminal content and resets the cursor to the top-left position. ### clearSelection - **clearSelection**(): void - Clears the current selection in the terminal. ### clearTextureAtlas - **clearTextureAtlas**(): void - Clears the terminal's texture atlas, forcing a re-render. ### deregisterCharacterJoiner - **deregisterCharacterJoiner**(joinerId: number): void - Deregisters a character joiner by its ID. ### dispose - **dispose**(): void - Disposes of the terminal, releasing resources. ### focus - **focus**(): void - Sets focus to the terminal. ### getSelection - **getSelection**(): string | undefined - Gets the currently selected text in the terminal. ### getSelectionPosition - **getSelectionPosition**(): { start: number, end: number } | undefined - Gets the start and end positions of the current selection. ### hasSelection - **hasSelection**(): boolean - Checks if there is any text currently selected in the terminal. ### input - **input**(data: string): void - Writes data to the terminal, simulating user input. ### loadAddon - **loadAddon**(addon: any): void - Loads an addon into the terminal. ### open - **open**(parent: HTMLElement): void - Opens the terminal in the specified parent HTML element. ### paste - **paste**(data: string): void - Pastes the provided data into the terminal. ### refresh - **refresh**(startRow: number, endRow: number): void - Refreshes a portion of the terminal viewport. ### registerCharacterJoiner - **registerCharacterJoiner**(handler: (text: string, ...params: any[]) => [number, string][]): number - Registers a character joiner function. ### registerDecoration - **registerDecoration**(decoration: IDecorationOptions): IDecoration | undefined - Registers a decoration on the terminal. ### registerLinkProvider - **registerLinkProvider**(provider: ILinkProvider): IDisposable - Registers a link provider for detecting links. ### registerMarker - **registerMarker**(line: number): IMarker | undefined - Registers a marker at the specified line number. ### reset - **reset**(): void - Resets the terminal to its initial state. ### resize - **resize**(cols: number, rows: number): void - Resizes the terminal to the specified number of columns and rows. ### scrollLines - **scrollLines**(lines: number): void - Scrolls the terminal content by the specified number of lines. ### scrollPages - **scrollPages**(pages: number): void - Scrolls the terminal content by the specified number of pages. ### scrollToBottom - **scrollToBottom**(): void - Scrolls the terminal to the bottom. ### scrollToLine - **scrollToLine**(line: number): void - Scrolls the terminal to the specified line. ### scrollToTop - **scrollToTop**(): void - Scrolls the terminal to the top. ### select - **select**(startCol: number, startRow: number, endCol: number, endRow: number): void - Selects a range of text in the terminal. ### selectAll - **selectAll**(): void - Selects all text in the terminal. ### selectLines - **selectLines**(startLine: number, endLine: number): void - Selects a range of lines in the terminal. ### write - **write**(data: string): void - Writes data to the terminal. ### writeln - **writeln**(data: string): void - Writes data to the terminal, followed by a newline. ``` -------------------------------- ### Display URL on Hover with Popup Source: https://xtermjs.org/docs/guides/link-handling Enhance link handling by displaying a popup with the full URL when hovering over a link. This includes logic to create, position, and remove the popup, and optionally display a modifier key prompt. The `linkHandler.hover` and `linkHandler.leave` callbacks are used for this functionality. ```javascript let _linkPopup; function removeLinkPopup = (event, text, range) { if (_linkPopup) { _linkPopup.remove(); _linkPopup = undefined; } } function showLinkPopup(event, text, range) { removeLinkPopup(event, text, range); let popup = document.createElement('div'); popup.classList.add('xterm-link-popup'); popup.style.position = 'absolute'; popup.style.top = (event.clientY + 25) + 'px'; popup.style.right = '0.5em'; popup.innerText = text; if (linkRequiresModifier()) { popup.appendChild(document.createElement('br')); const e2 = document.createElement('i'); e2.innerText = `(${isMac() ? 'Cmd' : 'Ctrl'}+Click to open link)`; popup.appendChild(e2); } const topElement = event.target.parentNode; topElement.appendChild(popup); const popupHeight = popup.offsetHeight; if (event.clientY + 25 + popupHeight > topNode.clientHeight) { let y = event.clientY - 25 - popupHeight; popup.style.top = (y < 0 ? 0 : y) + 'px'; } _linkPopup = popup; }; linkHandler.hover = showLinkPopup; linkHandler.leave = removeLinkPopup; ``` ```css div.xterm-link-popup { font-size: small; line-break: normal; /* auto doesn't work for WebKit */ padding: 4px; min-width: 15em; max-width: 80%; border: thin solid; border-radius: 6px; background: #6c4c4c; border-color: #150262; } ``` -------------------------------- ### Theme Option Source: https://xtermjs.org/docs/api/terminal/interfaces/iterminaloptions Specifies the color theme for the terminal. ```APIDOC ## `Optional` theme ### Description The color theme of the terminal. ### Type ITheme ``` -------------------------------- ### setWinPosition Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Moves the window to a specified position (x, y). This option is a boolean and has no default implementation. ```APIDOC ## setWinPosition ### Description Move window to [x, y]. ### Type boolean ### Defined in xterm.d.ts:696 ``` -------------------------------- ### getScreenSizeChars Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Reports the size of the screen in characters. The result is "CSI 9 ; height ; width t". No default implementation. ```APIDOC ## getScreenSizeChars ### Description Reports the dimensions of the terminal screen in characters (height and width). ### Parameters - **getScreenSizeChars** (boolean) - Optional - Set to true to request the screen size in characters. ### Response - **Success Response (200)**: The terminal will respond with a CSI sequence containing the screen height and width in characters. ``` -------------------------------- ### ILink Interface Methods Source: https://xtermjs.org/docs/api/terminal/interfaces/ilink Methods of the ILink interface. ```APIDOC ## Methods ### activate ▸ **activate**(`event`: MouseEvent, `text`: string): _void_ _Defined in xterm.d.ts:1430_ Calls when the link is activated. **Parameters:** Name | Type | Description ---|---|--- `event` | MouseEvent | The mouse event triggering the callback. `text` | string | The text of the link. **Returns:** _void_ * * * ### `Optional` dispose ▸ **dispose**(): _void_ _Defined in xterm.d.ts:1452_ Called when the link is released and no longer used by xterm.js. **Returns:** _void_ * * * ### `Optional` hover ▸ **hover**(`event`: MouseEvent, `text`: string): _void_ _Defined in xterm.d.ts:1440_ Called when the mouse hovers the link. To use this to create a DOM-based hover tooltip, create the hover element within `Terminal.element` and add the `xterm-hover` class to it, that will cause mouse events to not fall through and activate other links. **Parameters:** Name | Type | Description ---|---|--- `event` | MouseEvent | The mouse event triggering the callback. `text` | string | The text of the link. **Returns:** _void_ * * * ### `Optional` leave ▸ **leave**(`event`: MouseEvent, `text`: string): _void_ _Defined in xterm.d.ts:1447_ Called when the mouse leaves the link. **Parameters:** Name | Type | Description ---|---|--- `event` | MouseEvent | The mouse event triggering the callback. `text` | string | The text of the link. **Returns:** _void_ ``` -------------------------------- ### IMarker Methods Source: https://xtermjs.org/docs/api/terminal/interfaces/imarker Methods available on the IMarker interface. ```APIDOC ## Methods ### dispose ▸ **dispose**(): _void_ **Returns:** _void_ ``` -------------------------------- ### provideBufferElements Source: https://xtermjs.org/docs/api/terminal/interfaces/ibufferelementprovider Provides a document fragment or HTMLElement containing the buffer elements. ```APIDOC ## provideBufferElements() ### Description Provides a document fragment or HTMLElement containing the buffer elements. ### Method provideBufferElements ### Returns * DocumentFragment | HTMLElement ``` -------------------------------- ### getWinPosition Source: https://xtermjs.org/docs/api/terminal/interfaces/iwindowoptions Reports the terminal window position. Ps=13 reports window position, Ps=13 ; 2 reports text-area position. Result is "CSI 3 ; x ; y t". No default implementation. ```APIDOC ## getWinPosition ### Description Reports the position (x, y coordinates) of the terminal window or its text area. ### Parameters - **getWinPosition** (boolean) - Optional - Set to true to request the window position. Use `13;2` to request the text-area position. ### Response - **Success Response (200)**: The terminal will respond with a CSI sequence containing the x and y coordinates. ``` -------------------------------- ### IBufferLine Methods Source: https://xtermjs.org/docs/api/terminal/interfaces/ibufferline Methods available on the IBufferLine interface. ```APIDOC ## Methods ### getCell ▸ **getCell**(`x`: number, `cell?`: IBufferCell): *IBufferCell | undefined* Gets a cell from the line, or undefined if the line index does not exist. Note that the result of this function should be used immediately after calling as when the terminal updates it could lead to unexpected behavior. **Parameters:** Name | Type | Description ---|---|--- `x` | number | The character index to get. `cell?` | IBufferCell | Optional cell object to load data into for performance reasons. This is mainly useful when every cell in the buffer is being looped over to avoid creating new objects for every cell. **Returns:** *IBufferCell | undefined* ### translateToString ▸ **translateToString**(`trimRight?`: boolean, `startColumn?`: number, `endColumn?`: number): _string_ Gets the line as a string. Note that this is gets only the string for the line, not taking isWrapped into account. **Parameters:** Name | Type | Description ---|---|--- `trimRight?` | boolean | Whether to trim any whitespace at the right of the line. `startColumn?` | number | The column to start from (inclusive). `endColumn?` | number | The column to end at (exclusive). **Returns:** _string_ ``` -------------------------------- ### clear Source: https://xtermjs.org/docs/api/terminal/classes/terminal Clears the entire buffer of the terminal, making the current prompt line the new first line. ```APIDOC ## clear ### Description Clear the entire buffer, making the prompt line the new first line. ### Returns void ``` -------------------------------- ### Smooth Scroll Duration Option Source: https://xtermjs.org/docs/api/terminal/interfaces/iterminaloptions Sets the duration in milliseconds for smoothly scrolling between the origin and the target. Setting this to 0 disables smooth scrolling, causing instant scrolling. ```APIDOC ## `Optional` smoothScrollDuration ### Description The duration to smoothly scroll between the origin and the target in milliseconds. Set to 0 to disable smooth scrolling and scroll instantly. ### Type number ```