Class: Terminal

The class that represents an xterm.js terminal.

Hierarchy

Terminal

Implements

Index

Constructors

Properties

Methods


Constructors

constructor

new Terminal(options?: ITerminalOptions): Terminal

Defined in xterm.d.ts:307

Creates a new Terminal object.

Parameters:

Param Type Description
Optional options ITerminalOptions An object containing a set of options.

Returns: Terminal


Properties

cols

● cols: number

Defined in xterm.d.ts:296

The number of columns in the terminal’s viewport.


element

● element: HTMLElement

Defined in xterm.d.ts:281

The element containing the terminal.


markers

● markers: IMarker[]

Defined in xterm.d.ts:302

(EXPERIMENTAL) Get all markers registered against the buffer. If the alt buffer is active this will always return [].


rows

● rows: number

Defined in xterm.d.ts:291

The number of rows in the terminal’s viewport.


textarea

● textarea: HTMLTextAreaElement

Defined in xterm.d.ts:286

The textarea that accepts input for the terminal.


<Static> strings

● strings: ILocalizableStrings

Defined in xterm.d.ts:307

Natural language strings that can be localized.


Methods

addDisposableListener

addDisposableListener(type: string, handler: function): IDisposable

Defined in xterm.d.ts:390

Parameters:

Param Type
type string
handler function

Returns: IDisposable


addMarker

addMarker(cursorYOffset: number): IMarker

Defined in xterm.d.ts:447

(EXPERIMENTAL) Adds a marker to the normal buffer and returns it. If the alt buffer is active, undefined is returned.

Parameters:

Param Type Description
cursorYOffset number The y position offset of the marker from the cursor.

Returns: IMarker


attachCustomKeyEventHandler

attachCustomKeyEventHandler(customKeyEventHandler: function): void

Defined in xterm.d.ts:422

Attaches a custom key event handler which is run before keys are processed, giving consumers of xterm.js ultimate control as to what keys should be processed by the terminal and what keys should not.

Parameters:

Param Type Description
customKeyEventHandler function The custom KeyboardEvent handler to attach. This is a function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent the default action. The function returns whether the event should be processed by xterm.js.

Returns: void


blur

blur(): void

Defined in xterm.d.ts:319

Unfocus the terminal.

Returns: void


clear

clear(): void

Defined in xterm.d.ts:521

Clear the entire buffer, making the prompt line the new first line.

Returns: void


clearSelection

clearSelection(): void

Defined in xterm.d.ts:463

Clears the current terminal selection.

Returns: void


deregisterLinkMatcher

deregisterLinkMatcher(matcherId: number): void

Defined in xterm.d.ts:440

(EXPERIMENTAL) Deregisters a link matcher if it has been registered.

Parameters:

Param Type Description
matcherId number The link matcher’s ID (returned after register)

Returns: void


destroy

destroy(): void

Defined in xterm.d.ts:488

Destroys the terminal and detaches it from the DOM. deprecated: Use dispose() instead.

Returns: void


dispose

dispose(): void

Implementation of IDisposable.dispose

Defined in xterm.d.ts:481

Returns: void


emit

emit(type: string, data?: any): void

Implementation of IEventEmitter.emit

Defined in xterm.d.ts:388

Parameters:

Param Type
type string
Optional data any

Returns: void


focus

focus(): void

Defined in xterm.d.ts:324

Focus the terminal.

Returns: void


getOption

getOption(key: * “bellSound” | “bellStyle” | “cursorStyle” | “fontFamily” | “fontWeight” | “fontWeightBold” | “termName”*): string

getOption(key: * “allowTransparency” | “cancelEvents” | “convertEol” | “cursorBlink” | “debug” | “disableStdin” | “enableBold” | “macOptionIsMeta” | “rightClickSelectsWord” | “popOnBell” | “screenKeys” | “useFlowControl” | “visualBell”*): boolean

getOption(key: “colors”): string[]

getOption(key: * “cols” | “fontSize” | “letterSpacing” | “lineHeight” | “rows” | “tabStopWidth” | “scrollback”*): number

getOption(key: “handler”): function

getOption(key: string): any

Defined in xterm.d.ts:533

Retrieves an option’s value from the terminal.

Parameters:

Param Type Description
key “bellSound” | “bellStyle” | “cursorStyle” | “fontFamily” | “fontWeight” | “fontWeightBold” | “termName” The option key.

Returns: string

Defined in xterm.d.ts:538

Retrieves an option’s value from the terminal.

Parameters:

Param Type Description
key “allowTransparency” | “cancelEvents” | “convertEol” | “cursorBlink” | “debug” | “disableStdin” | “enableBold” | “macOptionIsMeta” | “rightClickSelectsWord” | “popOnBell” | “screenKeys” | “useFlowControl” | “visualBell” The option key.

Returns: boolean

Defined in xterm.d.ts:543

Retrieves an option’s value from the terminal.

Parameters:

Param Type Description
key “colors” The option key.

Returns: string[]

Defined in xterm.d.ts:548

Retrieves an option’s value from the terminal.

Parameters:

Param Type Description
key “cols” | “fontSize” | “letterSpacing” | “lineHeight” | “rows” | “tabStopWidth” | “scrollback” The option key.

Returns: number

Defined in xterm.d.ts:553

Retrieves an option’s value from the terminal.

Parameters:

Param Type Description
key “handler” The option key.

Returns: function

Defined in xterm.d.ts:558

Retrieves an option’s value from the terminal.

Parameters:

Param Type Description
key string The option key.

Returns: any


getSelection

getSelection(): string

Defined in xterm.d.ts:458

Gets the terminal’s current selection, this is useful for implementing copy behavior outside of xterm.js.

Returns: string


hasSelection

hasSelection(): boolean

Defined in xterm.d.ts:452

Gets whether the terminal has an active selection.

Returns: boolean


off

off(type: * “blur” | “focus” | “linefeed” | “selection” | “data” | “key” | “keypress” | “keydown” | “refresh” | “resize” | “scroll” | “title” | string, listener: *function): void

Defined in xterm.d.ts:386

Deregisters an event listener.

Parameters:

Param Type Description
type “blur” | “focus” | “linefeed” | “selection” | “data” | “key” | “keypress” | “keydown” | “refresh” | “resize” | “scroll” | “title” | string The type of the event.
listener function The listener.

Returns: void


on

on(type: * “blur” | “focus” | “linefeed” | “selection”, listener: *function): void

on(type: “data”, listener: function): void

on(type: “key”, listener: function): void

on(type: * “keypress” | “keydown”, listener: *function): void

on(type: “refresh”, listener: function): void

on(type: “resize”, listener: function): void

on(type: “scroll”, listener: function): void

on(type: “title”, listener: function): void

on(type: string, listener: function): void

Defined in xterm.d.ts:331

Registers an event listener.

Parameters:

Param Type Description
type “blur” | “focus” | “linefeed” | “selection” The type of the event.
listener function The listener.

Returns: void

Defined in xterm.d.ts:337

Registers an event listener.

Parameters:

Param Type Description
type “data” The type of the event.
listener function The listener.

Returns: void

Defined in xterm.d.ts:343

Registers an event listener.

Parameters:

Param Type Description
type “key” The type of the event.
listener function The listener.

Returns: void

Defined in xterm.d.ts:349

Registers an event listener.

Parameters:

Param Type Description
type “keypress” | “keydown” The type of the event.
listener function The listener.

Returns: void

Defined in xterm.d.ts:355

Registers an event listener.

Parameters:

Param Type Description
type “refresh” The type of the event.
listener function The listener.

Returns: void

Defined in xterm.d.ts:361

Registers an event listener.

Parameters:

Param Type Description
type “resize” The type of the event.
listener function The listener.

Returns: void

Defined in xterm.d.ts:367

Registers an event listener.

Parameters:

Param Type Description
type “scroll” The type of the event.
listener function The listener.

Returns: void

Defined in xterm.d.ts:373

Registers an event listener.

Parameters:

Param Type Description
type “title” The type of the event.
listener function The listener.

Returns: void

Defined in xterm.d.ts:379

Registers an event listener.

Parameters:

Param Type Description
type string The type of the event.
listener function The listener.

Returns: void


open

open(parent: HTMLElement): void

Defined in xterm.d.ts:411

Opens the terminal within an element.

Parameters:

Param Type Description
parent HTMLElement 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


refresh

refresh(start: number, end: number): void

Defined in xterm.d.ts:633

Tells the renderer to refresh terminal content between two rows (inclusive) at the next opportunity.

Parameters:

Param Type Description
start number The row to start from (between 0 and this.rows - 1).
end number The row to end at (between start and this.rows - 1).

Returns: void


registerLinkMatcher

registerLinkMatcher(regex: RegExp, handler: function, options?: ILinkMatcherOptions): number

Defined in xterm.d.ts:434

(EXPERIMENTAL) Registers a link matcher, allowing custom link patterns to be matched and handled.

Parameters:

Param Type Description
regex RegExp The regular expression to search for, specifically this searches the textContent of the rows. You will want to use \s to match a space ‘ ‘ character for example.
handler function The callback when the link is called.
Optional options ILinkMatcherOptions Options for the link matcher.

Returns: number The ID of the new matcher, this can be used to deregister.


reset

reset(): void

Defined in xterm.d.ts:638

Perform a full reset (RIS, aka ‘\x1bc’).

Returns: void


resize

resize(columns: number, rows: number): void

Defined in xterm.d.ts:397

Resizes the terminal.

Parameters:

Param Type
columns number
rows number

Returns: void


scrollLines

scrollLines(amount: number): void

Defined in xterm.d.ts:494

Scroll the display of the terminal

Parameters:

Param Type Description
amount number The number of lines to scroll down (negative scroll up).

Returns: void


scrollPages

scrollPages(pageCount: number): void

Defined in xterm.d.ts:500

Scroll the display of the terminal by a number of pages.

Parameters:

Param Type Description
pageCount number The number of pages to scroll (negative scrolls up).

Returns: void


scrollToBottom

scrollToBottom(): void

Defined in xterm.d.ts:510

Scrolls the display of the terminal to the bottom.

Returns: void


scrollToLine

scrollToLine(line: number): void

Defined in xterm.d.ts:516

Scrolls to a line within the buffer.

Parameters:

Param Type Description
line number The 0-based line index to scroll to.

Returns: void


scrollToTop

scrollToTop(): void

Defined in xterm.d.ts:505

Scrolls the display of the terminal to the top.

Returns: void


selectAll

selectAll(): void

Defined in xterm.d.ts:468

Selects all text within the terminal.

Returns: void


selectLines

selectLines(start: number, end: number): void

Defined in xterm.d.ts:475

Selects text in the buffer between 2 lines.

Parameters:

Param Type Description
start number The 0-based line index to select from (inclusive).
end number The 0-based line index to select to (inclusive).

Returns: void


setOption

setOption(key: * “fontFamily” | “termName” | “bellSound”, value: *string): void

setOption(key: * “fontWeight” | “fontWeightBold”, value: * null | “normal” | “bold” | “100” | “200” | “300” | “400” | “500” | “600” | “700” | “800” | “900”): void

setOption(key: “bellStyle”, value: * null | “none” | “visual” | “sound” | “both”*): void

setOption(key: “cursorStyle”, value: * null | “block” | “underline” | “bar”*): void

setOption(key: * “allowTransparency” | “cancelEvents” | “convertEol” | “cursorBlink” | “debug” | “disableStdin” | “enableBold” | “macOptionIsMeta” | “popOnBell” | “rightClickSelectsWord” | “screenKeys” | “useFlowControl” | “visualBell”, value: *boolean): void

setOption(key: “colors”, value: string[]): void

setOption(key: * “fontSize” | “letterSpacing” | “lineHeight” | “tabStopWidth” | “scrollback”, value: *number): void

setOption(key: “handler”, value: function): void

setOption(key: “theme”, value: ITheme): void

setOption(key: * “cols” | “rows”, value: *number): void

setOption(key: string, value: any): void

Defined in xterm.d.ts:565

Sets an option on the terminal.

Parameters:

Param Type Description
key “fontFamily” | “termName” | “bellSound” The option key.
value string The option value.

Returns: void

Defined in xterm.d.ts:571

Sets an option on the terminal.

Parameters:

Param Type Description
key “fontWeight” | “fontWeightBold” The option key.
value null | “normal” | “bold” | “100” | “200” | “300” | “400” | “500” | “600” | “700” | “800” | “900” The option value.

Returns: void

Defined in xterm.d.ts:577

Sets an option on the terminal.

Parameters:

Param Type Description
key “bellStyle” The option key.
value null | “none” | “visual” | “sound” | “both” The option value.

Returns: void

Defined in xterm.d.ts:583

Sets an option on the terminal.

Parameters:

Param Type Description
key “cursorStyle” The option key.
value null | “block” | “underline” | “bar” The option value.

Returns: void

Defined in xterm.d.ts:589

Sets an option on the terminal.

Parameters:

Param Type Description
key “allowTransparency” | “cancelEvents” | “convertEol” | “cursorBlink” | “debug” | “disableStdin” | “enableBold” | “macOptionIsMeta” | “popOnBell” | “rightClickSelectsWord” | “screenKeys” | “useFlowControl” | “visualBell” The option key.
value boolean The option value.

Returns: void

Defined in xterm.d.ts:595

Sets an option on the terminal.

Parameters:

Param Type Description
key “colors” The option key.
value string[] The option value.

Returns: void

Defined in xterm.d.ts:601

Sets an option on the terminal.

Parameters:

Param Type Description
key “fontSize” | “letterSpacing” | “lineHeight” | “tabStopWidth” | “scrollback” The option key.
value number The option value.

Returns: void

Defined in xterm.d.ts:607

Sets an option on the terminal.

Parameters:

Param Type Description
key “handler” The option key.
value function The option value.

Returns: void

Defined in xterm.d.ts:613

Sets an option on the terminal.

Parameters:

Param Type Description
key “theme” The option key.
value ITheme The option value.

Returns: void

Defined in xterm.d.ts:619

Sets an option on the terminal.

Parameters:

Param Type Description
key “cols” | “rows” The option key.
value number The option value.

Returns: void

Defined in xterm.d.ts:625

Sets an option on the terminal.

Parameters:

Param Type Description
key string The option key.
value any The option value.

Returns: void


write

write(data: string): void

Defined in xterm.d.ts:527

Writes text to the terminal.

Parameters:

Param Type Description
data string The text to write to the terminal.

Returns: void


writeln

writeln(data: string): void

Defined in xterm.d.ts:403

Writes text to the terminal, followed by a break line character (\n).

Parameters:

Param Type Description
data string The text to write to the terminal.

Returns: void


<Static> applyAddon

applyAddon(addon: any): void

Defined in xterm.d.ts:645

Applies an addon to the Terminal prototype, making it available to all newly created Terminals.

Parameters:

Param Type Description
addon any The addon to apply.

Returns: void