Class: AnsiTermDriver

AnsiTermDriver(params)

This is the base class from which AnsiTerm's communication drivers inherit the interface.

Internal drivers AnsiTermHttpDriver and AnsiTermWebSocketDriver are derivations of this class.

The programmer can write their own driver to connect the terminal to the backend that implements the specific application.

AnsiTerm uses public methods of this interface to communicate with the backend.

Programmers who need to write a custom driver are not required to implement all the methods provided by this interface. In particular, it is unlikely that it is ever necessary to rewrite the callback registration methods, since the base class already implements a sufficiently general mechanism.

A typical driver will redefine these methods:

  • _tx
  • _set_connection_state
  • start
  • _stop
  • close
  • setSize

Constructor

new AnsiTermDriver(params)

This is the base constructor. It is strongly recommended that the constructor of derived classes invokes the base constructor as its first instruction ("super(params)").

Parameters:
Name Type Description
params object

parameters, not used by the base, but stored.

Source:

Classes

AnsiTermDriver

Methods

_new_data(text)

This method is used by specialized drivers (extensions) to notify the client (i.e., the terminal) that there are new characters to process. If you are thinking of overriding it, think again.

Parameters:
Name Type Description
text string

the new sequence of characters

Source:

_set_connection_state()

This method may be used by extensions to notify a change in the connection state. Never override it.

Source:

_stop()

This method may be used by extensions to put the base object in a consistent state after an error. Do not override it.

Source:

_tx(text)

This method must be overridden by the extension to implement the protocol-specific transmitter. In its base version (defined only for debugging purposes), it sends characters back to the terminal (after some manipulation).

Parameters:
Name Type Description
text string

The sequence of chracters to send

Source:

close()

This method closes the communication and releases the resources. Extensions may override it, but it is advised to call the base method at some point in the override ("super.close()").

Source:

getConnectionState() → {boolean}

Used by AnsiTerm to read the current connection state. Extensions can set the connection state by invoking the _set_connection_state base method.

It is unlikely that a custom driver will ever need to override this method.

Source:
Returns:

The current connection state.

Type
boolean

registerOnConnectionChange(on_connection_change)

Used by AnsiTerm to register a notification callback to be notified of connection state changes. The callback is invoked when an extension calls the _set_connection_state base method.

It is unlikely that a custom driver will ever need to override this method.

Parameters:
Name Type Description
on_connection_change function

The callback function

Source:

registerOnDataReceived(on_data_received)

Used by AnsiTerm to register a notification callback to be notified of new incoming data. The callback is invoked when an extension calls the _new_data base method.

It is unlikely that a custom driver will ever need to override this method.

Parameters:
Name Type Description
on_data_received function

The callback function

Source:

send()

This method may be used by the terminal to send data (e.g., keyboard events). Never override it.

Source:

setSize(nlines, ncolumns)

This method is used by the terminal to set the terminal size. Extensions can override it to implement the corresponding protocol-specific operation.

Parameters:
Name Type Description
nlines *

Number of lines

ncolumns *

Number of columns

Source:

start()

This method opens the communication. Extensions may override it, but it is recommended to call the base method at some point in the override ("super.start()"), since it sends notifications to the client.

Source: