The DomTerm JavaScript class

A DomTerm instance encapsulates the state of a terminal emulator / console.

Functions and properties not documented here should be considered internal and (more) likely to change.

Function: new DomTerm (name)

Create a new DomTerm instance. The parameter name is a string. If you have multiple DomTerm instances, it is a good idea for the names to unique, but currently nothing depends on that.

Function: initializeTerminal (element)

Initialize the DomTerm, and associate it with the give element (which should be a <div> element that has class="domterm"). This creates the sub-structure of child elements of element.

Function: insertString (str)

Interpret and insert the characters of str. It may have ANSI/xterm escape sequences. This method is called by the DomTerm client code.

Function: eofSeen ()

This method is called by the DomTerm client code to notify DomTerm that the client has terminated. The backend repeatedly calls insertString and then finally calls eofSeen to signal end-of-file.

This function may be overridden. The default action is to call the close function of the current window.

Function: processInputCharacters (str)

Send str to the client, where str consists of typed characters and other events. This is a callback function that must be set by the client. This is called by the DomTerm code in terminal.js.

Function: reportEvent (name, data)

Called by DomTerm to notify the client that some (non-character) event happened. The default action calls processInputCharacter with a special sequence starting with 0xFD followed by the name, space, the data and a newline.

Function: setWindowSize (numRows, numColumns, availHeight, availWidth)

Called by DomTerm when the window changes size, or the (font) style changes so the number of rows or columns has changed. Is used to notify the client. The default behavior is to call reportEvent with a "WS" event type.

Function: doPaste ()

Handles a paste operation. May be called by client code. May also be overridden if needed; the default uses execCommand, which triggers a paste event. It is called by DomTerm if the user types Ctrl+Shift+V.

Function: pasteText (text)

Called by the paste event handler. Actually handle a paste event.

Function: doCopy ()

Handles a copy operation. May be called by client code. May also be overridden if needed; the default uses execCommand. It is called by DomTerm if the user types Ctrl+Shift+C.

Function: setInputMode (mode)

Set the input editing mode. The value 99 ('c') sets character mode (each keystroke is sent to the client); the value 108 ('l') sets line mode (local line editing with a complete line sent on enter); the value 97 ('a') sets automatic mode (switch between line and character modes depending on client pty state); the value 112 ('p') sets pipe mode (like line mode but with local echoing).

Function: doLineEdit (key, str)

Handle keyboard event when doing input line editing ourselves, rather than depending on the default action. This is used if the useDoLineEdit property is set. It is also used for the first character in automatic input editing mode. (In that case we can’t use the browser default action, since we first have to check the input mode of the client.)

Function: handleBell ()

Called when ctrl-G (the bell character) is seen. The default action is to do nothing.

Called on a click event on a <a> link element. The default action is to call preventDefault on the event, and then call reportEvent with an "ALINK" type event. (We can’t let the browser do its default action since that would replace the current DomTerm page.)

Function: setWindowTitle (title, option)

Set the title of the containing window. Called by DomTerm when it sees certain xterm-style escape sequences. Calls updateWindowTitle(formatWindowTitle()).

Function: formatWindowTitle ()

Returns a suitable string for a window title, based on various properies.

Function: updateWindowTitle (title)

Actualy set the window title - which is usually the result of formatWindowTitle().

Function: elementInfo (tag, parents)

Overridable function called by the HTML sanitizer.

Function: allowAttribute (name, value elementInfo, parents)

Overridable function called by the HTML sanitizer.