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 |
Object | string | Configuration parameters or the ID of the div element to create the terminal in. Properties
|
Classes
Methods
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.
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. |
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 |
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