Constructor
new AnsiTerm(params)
Creates an AnsiTerm instance.
If "params" is not specified, the default configuration is applied (80x25, title bar, status bar, soft keyboard, HTTP protocol, "document.body" as parent).
If "params" is a string, it is interpreted as the container ID in which the terminal takes place.
Parameters:
Name | Type | Description |
---|---|---|
params |
* | optional parameters, as a single string or set of key-value pairs. |
Classes
Methods
cancelOnAppCursorKeyChange(cb)
This method removes the callback registered by registerOnAppCursorKeyChange
.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to remove. |
cancelOnCopy(cb)
This method removes the callback registered by registerOnCopy
.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to remove. |
cancelOnFreezeChange(cb)
This method removes the callback registered by registerOnFreezeChange
.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to remove. |
cancelOnStatusChange(cb)
This method removes the callback registered by registerOnStatusChange
.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to remove. |
cancelOnTitleChange(cb)
This method removes the callback registered by registerOnTitleChange
.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to remove. |
clearSelection()
This method clears the selection and returns the focus to the terminal.
clipboardCopyAsAnsiSequence()
This method copies the selection to the clipboard. The selection is copied as text, possibly containing ANSI sequences to reproduce the character attributes of the on-screen text.
clipboardCopyAsHtml()
This method copies the selection to the clipboard. The selection is copied as HTML, reproducing the characters of the on-screen text and their attributes.
clipboardCopyAsRichText()
This method copies the selection to the clipboard. The selection is copied as Rich Text.
NOTE: this method is still under development, and its behavior may change in future releases.
The text is actually stored as HTML, but trailing spaces in lines are discarded. Since the goal of this method is to capture data suited to be pasted into word processors, some adjustments may be useful (e.g., color correction to deal with typical white backgrounds).
clipboardCopyAsText()
This method copies the selection to the clipboard. The selection is copied as plain text.
clipboardPaste()
This method implements the clipboard "paste" function.
close()
This method closes the terminal's communication channel and destroys the terminal.
focus()
This method sets the focus on the terminal. It is used to make the terminal ready to receive keyboard input.
getCanvas() → {HTMLCanvasElement}
This method returns the canvas element used by the terminal.
Returns:
The canvas element.
- Type
- HTMLCanvasElement
registerOnAppCursorKeyChange(cb)
This method adds a callback that the terminal will invoke each time the application cursor
key mode changes, i.e., when the "set application cursor" ANSI sequence is received.
The callback receives the new application cursor mode as a parameter.
Multiple callbacks may be registered in this way.
The callbacks can be removed by calling the cancelOnAppCursorKeyChange
method.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to add. |
registerOnCopy(cb)
This method adds a callback that the terminal will invoke each time
a some kind of "copy on clipboard" operation is performed.
The callback receives the content copied to the clipboard as a string.
The callback is called with the second argument set to true if the
content is copied as text, and false if it is copied as a blob.
Multiple callbacks may be registered in this way.
The callbacks can be removed by calling the cancelOnCopy
method.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to add. |
registerOnFreezeChange(cb)
This method adds a callback that the terminal will invoke each time one of these events happens:
- the terminal freezes, i.e., stops updating the screen and accumulates incoming
characters instead of showing them. A "freeze" may be generated by entering
the mouse selection state or programmatically by calling
toggleFreezeState
. - the terminal is frozen, and new characters are received.
- the terminal exits the freeze state.
The callback receives two parameters:
- a boolean parameter, "true" if the terminal is frozen, "false" if not,
- the number of characters received since the terminal has been frozen.
Multiple callbacks may be registered in this way.
The callbacks can be removed by calling the cancelOnFreezeChange
method.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to add. |
registerOnStatusChange(cb)
Adds a callback that the terminal will invoke when the communication state changes. The callback receives a boolean parameter: "true" if the communication is established, "false" if not.
Multiple callbacks may be registered in this way.
The callbacks can be removed by calling the cancelOnStatusChange
method.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to add. |
registerOnTitleChange(cb)
This method adds a callback that the terminal will invoke each time the title changes,
i.e., when the "set title" ANSI sequence is received.
The callback receives the new title as a parameter.
Multiple callbacks may be registered in this way.
The callbacks can be removed by calling the cancelOnTitleChange
method.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback function to add. |
resize(nLines, nColumns)
This method resizes the terminal to the given number of lines and columns. The selection and the viewpoint are cleared, and the cursor is adjusted accordingly. The alternate screen is simply cleared, as it is usually redrawn when the terminal is resized.
Parameters:
Name | Type | Description |
---|---|---|
nLines |
number | The number of lines for the terminal. |
nColumns |
number | The number of columns for the terminal. |
selectAll()
This method selects the entire screen. It implements the "Select all" button function.
sendKeyByKeyEvent(key)
This method sends the ANSI sequence corresponding to the given keyboard event object to the communication channel used by the terminal.
A key event is an object containing key-related members as produced by a real key event. The object is not required to be a real "event", as only a subset of members is needed:
- "key",
- "code",
- "composed",
- "ctrlKey",
- "altKey",
- "metaKey".
Example: the TAB key is represented by this object:
{ key: 'Tab', code: 'Tab', composed: false, ctrlKey: false, altKey: false, metaKey: false }
Parameters:
Name | Type | Description |
---|---|---|
key |
KeyEventObject | the key event to send |
sendText(text)
This method sends the given sequence of characters to the communication channel used by the terminal.
Parameters:
Name | Type | Description |
---|---|---|
text |
string | the text to send |
setBell(enabled, dration, frequency, decay) → {void}
This method allows you to configure the bell sound parameters for the terminal. The bell sound is played when the terminal receives a BEL character (0x07). You can enable or disable the bell sound, set its duration, frequency, and decay ratio. The default values are:
enabled
: trueduration
: 0.5 secondsfrequency
: 1760 Hz (A6 note)decay
: 0.9998 (decay ratio between a sample and the next one, i.e., next/current)
Parameters:
Name | Type | Description |
---|---|---|
enabled |
boolean | Whether the bell sound is enabled. |
dration |
number | The duration of the bell sound in seconds (no changes if undefined). |
frequency |
number | The frequency of the bell sound in Hz (no changes if undefined). |
decay |
number | The decay ratio of the bell sound (no changes if undefined). |
Returns:
- Type
- void
Example
term.setBell(true, 0.5, 1760, 0.9);
write(text)
This method writes the given sequence of characters. The sequence is processed by the ANSI interpreter, which modifies the screen accordingly.
Parameters:
Name | Type | Description |
---|---|---|
text |
string | The text to write to the terminal. |
(static) getVersion() → {string}
This method retrieves the version string of "xwterm.js".
Returns:
The version string of this package.
- Type
- string