FabGL
ESP32 Display Controller and Graphics Library
Terminal Class Reference

An ANSI-VT100 compatible display terminal. More...

#include <terminal.h>

Inherits Stream.

Public Member Functions

void activate (TerminalTransition transition=TerminalTransition::None)
 Activates this terminal for input and output. More...
 
int available ()
 Gets the number of codes available in the keyboard queue. More...
 
int availableForWrite ()
 Determines number of codes that the display input queue can still accept. More...
 
bool begin (BaseDisplayController *displayController, int maxColumns=-1, int maxRows=-1, Keyboard *keyboard=nullptr)
 Initializes the terminal. More...
 
Canvascanvas ()
 Gets associated canvas object. More...
 
void clear (bool moveCursor=true)
 Clears the screen. More...
 
void connectLocally ()
 Permits using of terminal locally. More...
 
void connectSerialPort (HardwareSerial &serialPort, bool autoXONXOFF=true)
 Connects a remote host using the specified serial port. More...
 
void connectSerialPort (uint32_t baud, uint32_t config, int rxPin, int txPin, FlowControl flowControl, bool inverted=false, int rtsPin=-1, int ctsPin=-1)
 Connects a remote host using UART. More...
 
bool CTSStatus ()
 Reports current CTS signal status. More...
 
void deactivate ()
 Deactivates this terminal. More...
 
void disableSerialPortRX (bool value)
 Disables/Enables serial port RX. More...
 
void disconnectLocally ()
 Avoids using of terminal locally. More...
 
void enableCursor (bool value)
 Enables or disables cursor. More...
 
void end ()
 Finalizes the terminal. More...
 
void flowControl (bool enableRX)
 Allows/disallows host to send data. More...
 
bool flowControl ()
 Checks whether host can receive data. More...
 
void flush (bool waitVSync)
 Waits for all codes sent to the display has been processed. More...
 
void flush ()
 Waits for all codes sent to the display has been processed. More...
 
int getColumns ()
 Returns the number of columns. More...
 
int getRows ()
 Returns the number of lines. More...
 
bool isActive ()
 Determines if this terminal is active or not. More...
 
Keyboardkeyboard ()
 Gets associated keyboard object. More...
 
void loadFont (FontInfo const *font)
 Sets the font to use. More...
 
void localInsert (uint8_t c)
 Injects keys into the keyboard queue. More...
 
void localWrite (uint8_t c)
 Injects keys into the keyboard queue. More...
 
void localWrite (char const *str)
 Injects a string of keys into the keyboard queue. More...
 
int peek ()
 Reads a code from the keyboard without advancing to the next one. More...
 
void pollSerialPort ()
 Pools the serial port for incoming data. More...
 
int read ()
 Reads codes from keyboard. More...
 
int read (int timeOutMS)
 Reads codes from keyboard specyfing timeout. More...
 
bool RTSStatus ()
 Reports current RTS signal status. More...
 
void send (uint8_t c)
 Like localWrite() but sends also to serial port if connected. More...
 
void send (char const *str)
 Like localWrite() but sends also to serial port if connected. More...
 
void setBackgroundColor (Color color, bool setAsDefault=true)
 Sets the background color. More...
 
void setColorForAttribute (CharStyle attribute, Color color, bool maintainStyle)
 Selects a color for the specified attribute. More...
 
void setColorForAttribute (CharStyle attribute)
 Disables color for the specified attribute. More...
 
void setForegroundColor (Color color, bool setAsDefault=true)
 Sets the foreground color. More...
 
void setLogStream (Stream &stream)
 Sets the stream where to output debugging logs. More...
 
void setRTSStatus (bool value)
 Sets RTS signal status. More...
 
void setTerminalType (TermType value)
 Sets the terminal type to emulate. More...
 
SoundGeneratorsoundGenerator ()
 Gets embedded sound generator. More...
 
TermInfo const & terminalType ()
 Determines current terminal type. More...
 
void unRead (uint8_t c)
 Injects keys into the keyboard queue. More...
 
bool waitFor (int value, int timeOutMS=-1)
 Wait for a specific code from keyboard, discarding all previous codes. More...
 
size_t write (const uint8_t *buffer, size_t size)
 Sends specified number of codes to the display. More...
 
size_t write (uint8_t c)
 Sends a single code to the display. More...
 
bool XOFFStatus ()
 Reports whether TX is active. More...
 

Public Attributes

Delegate< char const * > onUserSequence
 Delegate called whenever a new user sequence has been received. More...
 
Delegate< VirtualKey *, bool > onVirtualKey
 Delegate called whenever a new virtual key is received from keyboard. More...
 
Delegate< VirtualKeyItem * > onVirtualKeyItem
 Delegate called whenever a new virtual key is received from keyboard, including shift states. More...
 

Static Public Attributes

static int inputConsumerTaskStackSize = 2048
 Stack size of the task that processes Terminal input stream. More...
 
static int inputQueueSize = 1024
 Number of characters the terminal can "write" without pause (increase if you have loss of characters in serial port). More...
 
static int keyboardReaderTaskStackSize = 2048
 Stack size of the task that reads keys from keyboard and send ANSI/VT codes to output stream in Terminal. More...
 

Detailed Description

An ANSI-VT100 compatible display terminal.

Implements most of common ANSI, VT52, VT100, VT200, VT300, VT420 and VT500 escape codes, like non-CSI codes (RIS, IND, DECID, DECDHL, etc..),
like CSI codes (private modes, CUP, TBC, etc..), like CSI-SGR codes (bold, italic, blinking, etc...) and like DCS codes (DECRQSS, etc..).
Supports conversion from PS/2 keyboard virtual keys to ANSI or VT codes (keypad, cursor keys, function keys, etc..).

Terminal can receive codes to display from Serial Port or it can be controlled directly from the application. In the same way Terminal can send keyboard codes to a Serial Port or directly to the application.

For default it supports 80x25 or 132x25 characters at 640x350. However any custom resolution and text buffer size is supported specifying a custom font.

There are three cursors styles (block, underlined and bar), blinking or not blinking.

Terminal inherits from Stream so applications can use all Stream and Print input and output methods.

Terminal passes 95/110 of VTTEST VT100/VT102 Compatibility Test Score Sheet.

Example 1:

fabgl::VGAController VGAController;
fabgl::PS2Controller PS2Controller;
fabgl::Terminal      Terminal;

// Setup 80x25 columns loop-back terminal (send what you type on keyboard to the display)
void setup() {
  PS2Controller.begin(PS2Preset::KeyboardPort0);

  VGAController.begin();
  VGAController.setResolution(VGA_640x350_70HzAlt1);

  Terminal.begin(&VGAController);
  Terminal.connectLocally();      // to use Terminal.read(), available(), etc..
  Terminal.enableCursor(true);
}

void loop() {
  if (Terminal.available()) {
    char c = Terminal.read();
    switch (c) {
      case 0x7F:       // DEL -> backspace + ESC[K
        Terminal.write("\b\e[K");
        break;
      case 0x0D:       // CR  -> CR + LF
        Terminal.write("\r\n");
        break;
      case 32 ... 126: // printable chars
        Terminal.write(c);
        break;
    }
  }
}

Example 2:

fabgl::VGAController VGAController;
fabgl::PS2Controller PS2Controller;
fabgl::Terminal      Terminal;

// Setup 80x25 columns terminal using UART2 to communicate with the server,
// VGA to display output and PS2 device as keyboard input
void setup() {
  Serial2.begin(115200);

  PS2Controller.begin(PS2Preset::KeyboardPort0);

  VGAController.begin();
  VGAController.setResolution(VGA_640x350_70HzAlt1);

  Terminal.begin(&VGAController);
  Terminal.connectSerialPort(Serial2);
  Terminal.enableCursor(true);
}

void loop() {
  Terminal.pollSerialPort();
}
Examples:
Others/KeyboardScanCodes/KeyboardScanCodes.ino, Others/KeyboardVirtualKeys/KeyboardVirtualKeys.ino, SSD1306_OLED/128x32/SimpleTerminalOut/SimpleTerminalOut.ino, SSD1306_OLED/128x64/NetworkTerminal/NetworkTerminal.ino, SSD1306_OLED/128x64/RTClock/RTClock.ino, SSD1306_OLED/128x64/SimpleTerminalOut/SimpleTerminalOut.ino, ST7789_TFT/240x240/SimpleTerminalOut/SimpleTerminalOut.ino, VGA/Altair8800/Altair8800.ino, VGA/AnsiTerminal/AnsiTerminal.ino, VGA/LoopbackTerminal/LoopbackTerminal.ino, VGA/MultitaskingCPM/MultitaskingCPM.ino, VGA/NetworkTerminal/NetworkTerminal.ino, VGA/SimpleTerminalOut/SimpleTerminalOut.ino, VGA/SimpleTextTerminalOut/SimpleTextTerminalOut.ino, and VGA/Songs/Songs.ino.

Definition at line 953 of file terminal.h.


The documentation for this class was generated from the following files: