ESPTerm emulates VT102 (pictured) with some additions from later VT models and xterm
.
All commonly used attributes and commands are supported.
ESPTerm is capable of displaying ncurses applications such as Midnight Commander using agetty.
ESPTerm accepts UTF-8 characters received on the communication UART and displays them on the screen, interpreting some codes as Control Characters. Those are e.g. Carriage Return (13), Line Feed (10), Tab (9), Backspace (8) and Bell (7). Escape sequences start with the control character ESC (27), followed by any number of ASCII characters forming the body of the command.
Examples on this help page use the following symbols for special characters and command types: (spaces are for clarity only, DO NOT include them in the commands!)
Name | Symbol | ASCII | C string | Function |
---|---|---|---|---|
ESC | \e |
ESC (27) |
"\e" , "\x1b" , "\033" |
Introduces an escape sequence. (Note: \e is a GCC extension) |
Bell | \a |
BEL (7) |
"\a" , "\x7" , "\07" |
Audible beep |
String Terminator | ST |
ESC \ (27 92) or \a (7)
|
"\x1b\\", |
Terminates a string command (\a can be used as an alternative) |
Control Sequence Introducer | CSI |
ESC [ |
"\x1b[" |
Starts a CSI command. Examples: \e[?7;10h , \e[2J |
Operating System Command | OSC |
ESC ] |
"\x1b]" | Starts an OSC command. Is followed by a command string terminated by ST . Example: \e]0;My Screen Title\a |
Select Graphic Rendition | SGR |
CSI n ; n ; n m |
"\x1b[1;2;3m" |
Set text attributes, like color or style. 0 to 10 numbers can be used, \e[m is treated as \e[0m |
There are also some other commands that don't follow the CSI, SGR or OSC pattern, such as \e7
or
\e#8
. A list of the most important escape sequences is presented in the following sections.
The initial screen size, title text and button labels can be configured in Terminal Settings.
Screen updates are sent to the browser through a WebSocket after some time of inactivity on the communication UART (called "Redraw Delay"). After an update is sent, at least a time of "Redraw Cooldown" must elapse before the next update can be sent. Those delays are used is to avoid burdening the server with tiny updates during a large screen repaint. If you experience issues (broken image due to dropped bytes), try adjusting those config options. It may also be useful to try different baud rates.
All text attributes are set using SGR commands like \e[10;20;30m
, with up to 10 numbers separated by semicolons.
To restore all attributes to their default states, use SGR 0: \e[0m
or \e[m
.
Those are the supported text attributes SGR codes:
Style | Enable | Disable |
---|---|---|
Bold | 1 | 21, 22 |
Faint | 2 | 22 |
Italic | 3 | 23 |
Underlined | 4 | 24 |
Blink | 5 | 25 |
Inverse | 7 | 27 |
9 | 29 | |
𝔉𝔯𝔞𝔨𝔱𝔲𝔯 | 20 | 23 |
Colors are set using SGR commands (like \e[10;20;30m
). The following tables list the SGR codes to use.
Selected colors are used for any new text entered, as well as for empty space when using line and screen clearing commands.
The configured default colors can be restored using SGR 39 for foreground and SGR 49 for background.
The actual color representation depends on a color theme which can be selected in Terminal Settings.
The user can input text using their keyboard, or on Android, using the on-screen keyboard which is open using a button beneath the screen. Supported are all printable characters, as well as many control keys, such as arrows, Ctrl+letters and function keys. Sequences sent by function keys are based on VT102 and xterm.
The codes sent by Home, End, F1-F4 and cursor keys are affected by various keyboard modes (Application Cursor Keys, Application Numpad Mode, SS3 Fn Keys Mode). Some can be set in the Terminal Settings, others via commands.
Here are some examples of control key codes:
Key | Code | Key | Code |
---|---|---|---|
Up | \e[A |
F1 | \eOP |
Down | \e[B |
F2 | \eOQ |
Right | \e[C |
F3 | \eOR |
Left | \e[D |
F4 | \eOS |
Home | \eOH |
F5 | \e[15~ |
End | \eOF |
F6 | \e[17~ |
Insert | \e[2~ |
F7 | \e[18~ |
Delete | \e[3~ |
F8 | \e[19~ |
Page Up | \e[5~ |
F9 | \e[20~ |
Page Down | \e[6~ |
F10 | \e[21~ |
Enter | CR (13) |
F11 | \e[23~ |
Ctrl+Enter | LF (10) |
F12 | \e[24~ |
Tab | TAB (9) |
ESC | ESC (27) |
Backspace | BS (8) |
Ctrl+A..Z | ASCII 1-26 |
The blue buttons under the screen send ASCII codes 1, 2, 3, 4, 5, which incidentally correspond to Ctrl+A,B,C,D,E. This choice was made to make button press parsing as simple as possible.
ESPTerm implements standard mouse tracking schemes based on Xterm. Mouse tracking can be used to add powerful user interactions such as on-screen buttons, draggable on-screen sliders or dials, menus etc.
TODOThe coordinates are 1-based, origin is top left. The cursor can move within the entire screen, or in the active Scrolling Region if Origin Mode is enabled.
After writing a character, the cursor advances to the right. If it has reached the end of the row, it stays on the same line, but writing the next character makes it jump to the start of the next line first, scrolling up if needed. If Auto-wrap mode is disabled, the cursor never wraps or scrolls the screen.
Legend: Italic letters such as n are ASCII numbers that serve as arguments, separated with a semicolon. If an argument is left out, it's treated as 0 or 1, depending on what makes sense for the command.
Code | Meaning |
---|---|
\e[nA \e[nB \e[nC \e[nD |
Move cursor up (A), down (B), right (C), left (D) |
\e[nF \e[nE |
Go n lines up (F) or down (E), start of line |
\e[rd \e[cG \e[r;cH |
Go to absolute position - row (d), column (G), or both (H). Use \e[H to go to 1,1.
|
\e[6n | Query cursor position. Sent back as \e[r;cR . |
Code | Meaning |
---|---|
\e[s \e[u |
Save (s) or restore (u) cursor position |
\e7 \e8 |
Save (7) or restore (8) cursor position and attributes |
Code | Meaning |
---|---|
\e[a;br | Set scrolling region to rows a through b and go to 1,1. By default, the scrolling region spans the entire screen height. The cursor can leave the region using absolute position commands, unless Origin Mode (see below) is active. |
\e[?6h \e[?6l |
Enable (h) or disable (l) Origin Mode and go to 1,1. In Origin Mode, all coordinates are relative to the Scrolling Region and the cursor can't leave the region. |
\e[nS \e[nT |
Move contents of the Scrolling Region up (S) or down (T), pad with empty lines of the current background color. |
Code | Meaning |
---|---|
\eH | Set tab stop at the current column. There are, by default, tabs every 8 columns. |
\e[nI \e[nZ |
Advance (I) or go back (Z) n tab stops or end/start of line. ASCII TAB (9) is equivalent to \e[1I |
\e[0g \e[3g |
Clear tab stop at the current column (0), or all columns (3). |
Code | Meaning |
---|---|
\e[?7h \e[?7l |
Enable (h) or disable (l) cursor auto-wrap and screen auto-scroll |
\e[?25h \e[?25l |
Show (h) or hide (l) the cursor |
Legend: Italic letters such as n are ASCII numbers that serve as arguments, separated with a semicolon. If an argument is left out, it's treated as 0 or 1, depending on what makes sense for the command.
Code | Meaning |
---|---|
\e[mJ | Clear part of screen. m: 0 - from cursor, 1 - to cursor, 2 - all |
\e[mK | Erase part of line. m: 0 - from cursor, 1 - to cursor, 2 - all |
\e[nX | Erase n characters in line. |
\e[nL \e[nM |
Insert (L) or delete (M) n lines. Following lines are pulled up or pushed down. |
\e[n@ \e[nP |
Insert (@) or delete (P) n characters. The rest of the line is pulled left or pushed right. Characters going past the end of line are lost. |
ESPTerm implements Alternate Character Sets as a way to print box drawing characters and special symbols. A character set can change what each received ASCII character is printed as on the screen (eg. "{" is "π" in codepage 0). The implementation is based on the original VT devices. Since ESPTerm also fully supports UTF-8, you can probably ignore this feature and use Unicode directly. It's added for compatibility with some programs that use this.
The following codepages are implemented:
To see what character maps to which symbol, look in the source code or try it. All codepages use codes 32-127, 32 being space.
There are two character set slots, G0 and G1.
Those slots are selected as active using ASCII codes Shift In and Shift Out (those originally served for shifting
a red-black typewriter tape). Each slot (G0 and G1) can have a different codepage assigned. G0 and G1 and the active slot number are
saved and restored with the cursor and cleared with a screen reset (\ec
).
The following commands are used:
Code | Meaning |
---|---|
\e(x | Set G0 = codepage x |
\e)x | Set G1 = codepage x |
SO (14) | Activate G0 |
SI (15) | Activate G1 |
It's possible to dynamically change the screen title text and action button labels. Setting an empty label to a button makes it look disabled. The buttons send ASCII 1-5 when clicked. Those changes are not retained after restart.
Code | Meaning |
---|---|
\ec | Clear screen, reset attributes and cursor. The screen size, title and button labels remain unchanged. |
\e[5n |
Query device status, ESPTerm replies with \e[0n "device is OK".
Can be used to check if the terminal has booted up and is ready to receive commands. |
CAN (24) | This ASCII code is not a command, but is sent by ESPTerm when it becomes ready to receive commands. When this code is received on the UART, it means ESPTerm has restarted and is ready. Use this to detect spontaneous restarts which require a full screen repaint. |
\e]0;title\a | Set screen title (this is a standard OSC command) |
\e]81;btn1\a \e]82;btn2\a \e]83;btn3\a \e]84;btn4\a \e]85;btn5\a |
Set button 1-5 label - eg. \e]81;Yes\a
sets the first button text to "Yes". |
\e[8;r;ct | Set screen size (this is a command borrowed from xterm) |