Synchronet v3.19b-Win32 (install) has been released (Jan-2022).

You can donate to the Synchronet project using PayPal.

This is an old revision of the document!


CTerm

CTerm is the ANSI parsing code maintained as part of ciolib (and used by SyncTERM). This page is basically a pretty version of the cterm.txt file in git, as of 72305c4cfe7afe31064422694beac53a9fe8e5f3

The text file is still the normative reference, but this may serve as a friendlier source.

CTerm terminal characteristics

End of line behaviour (wrapping)

The cursor is moved to the first character of the next line as soon as a character is written to the last column of the current line, not on the next character. A tab will wrap to the next line only if the current cursor position is the last character on the line. This behavior is often surprising to people who are used to VT emulators which implement the LCF as documented in STD-070, who expect the cursor to “stick” in the last column until the next character is received.

There are two settable flags that will impact the default behaviour.

CSI ? 7 l will disable wrapping at the end of line completely, and any characters written to the last column will not move the cursor at all, overwriting the existing charater. Default behaviour can be restored with CSI ? 7 h.

If the CSI = 4 h sequence is received, CTerm will enable LCF mode as documented in STD-070, and CSI = 4 l will restore default behaviour. CSI = 5 h will set LCF mode and disable CSI = 4 l, as well as cause LCF to remain enabled across an ESC c (RIS).

Specifically, the LCF will be set when displaying a printable character advances the cursor to the right margin, and cleared by any of the following being received: CSI ? 6 h, CSI ? 6 l, CSI ? 7 l, CSI @, CSI A, CSI B, CSI a, CSI j, CSI H, CSI f, CSI I, CSI Y, CSI J, CSI K, CSI P, CSI X, CSI r, ESC E, ESC M, CR, LF, BS, TAB, Any normal printable character when the cursor is at the right margin (of the screen or scrollable area).

Control Characters

Name Hex Description
NUL 0x00 No action is taken unless doorway mode is enabled. In doorway mode, indicates that the next character is a literal character. The IBM CP437 character will be displayed. This allows ESC and other control characters to be placed on the screen.
BEL 0x07 Terminal will beep
BS 0x08 Non-destructive backspace. Moves cursor position to the previous column unless the current column is the first, in which case no operation is performed.
HT 0x09 Moves to the next horizontal tab stop. Does not overwrite any characters in between. If there are no tab stops left in the line, moves to the first position of the next line. If the starting position is on the last line, will perform a scroll, filling the new line at bottom with the current attribute.
LF 0x0A Move cursor position to same column of the next row. If current row is the last row, scrolls the screen up and fills the new row with the current attribute.
CR 0x0D Move cursor position to column 1 of the current line
ESC 0x1B Introduces a control code. The ESC and the next byte together form the control code. If the control code is not valid, the ESC is ignored.

Control Codes

Control codes are in the following format: ESC {'0' (ZERO) to '~'} Legal combinations which are not handled are silently dropped.

Mnemonic Name Sequence Description
NEL Next Line ESC E Moves to the line home position of the next line. (Same as CR LF)
HTS Set Tab ESC H Sets a tab stop at the current column. ECMA-048
RI Reverse Line Feed ESC M Move up one line. ECMA-048
DCS Device Control String ESC P Begins a string consisting of the characters 0x08 - 0x0d and 0x20-0x7e, terminated by a String Terminator (ST)
SOS Start of String ESC X As the above strings, but may contain any characters except a Start Of String sequence or a String Terminator sequence. The string is currently ignored.
ST String Terminator ESC \ Ends a string sequence
OSC Operating System Command ESC ] Begins a string consisting of the characters 0x08 - 0x0d and 0x20-0x7e, terminated by a String Terminator (ST)
PM Privacy Message ESC ^ Begins a string consisting of the characters 0x08 - 0x0d and 0x20-0x7e, terminated by a String Terminator (ST) The string is currently ignored.
APS Application Program String ESC _ Begins a string consisting of the characters 0x08 - 0x0d and 0x20-0x7e, terminated by a String Terminator (ST)

Supported DCS string values

CTerm loadable font

CTerm:Font:p1:<b64>

Indicates the string is a loadable font. (CTerm 1.213)

p1 is a font slot number, which must be higher than the last default defined font (See CSI sp D for list of predefined fonts). <b64> is the base64 encoded font data. Font size is deduced from the size of the data. This replaces the now deprecated CSI = Ps1 ; Ps2 {

Sixel Sequence

[ p1 [ ; p2 ] ] q

Defaults: p1 = 0 p2 = 0

Indicates the string is a sixel sequence.

p1 selects the vertical height of a single pixel. This may be overridden by the raster attributes command, and is deprecated.

Supported values

Value Vertical Size
0,1,5,6 2 pixels
2 5 pixels
3,4 3 pixels
7,8,9 1 pixel

p2 indicates if unset sixels should be set to the current background colour. If p2 is 1, positions specified as 0 remain at their current colour.

Any additional parameters are ignored.

The rest of the string is made up of sixel data characters and sixel control functions. Sixel data characters are in the rage of '?' (0x3f) to '~' (0x7e). Each sixel data character represents six vertical pixels. The data is extracted by subtracting 0x3f from the ASCII value of the character. The least significant bit is the topmost pixel.

Sixel Control Functions
String Name Description
! Pn X Graphics Repeat Introducer The character X is repeated Pn times.
p1 ; p2 [ ; p3 [ ; p4 ] ] Raster Attributes p1 indicates the vertical size in pixels of each sixel.
p2 indicates the horizontal size in pixels.
p3 and p4 define the height and width (in sixels) respectively of a block to fill with the background colour. This block may not extend past the current bottom of the screen. If any pixel data characters proceed this command, it is ignored.
# p1 Colour Select Selects the current foreground colour from the sixel palette.
# p1 ; p2 ; p3 ; p4 ; p5 Palette map Defines sixel palette entry p1 and sets it as the current foreground colour. p2 specifies the colour space to define the colour in, the only supported value is 2. p3, p4, and p5 specify the red, green, and blue content as a percentage (0-100).
$ Graphics Carriage Return Returns the active position to the left border of the same sixel row. Generally, one pass per colour is used. In passes after the first one, sixels with a value of zero are not overwritten with the background colour.
- Graphics New Line Moves the active position to the left border of the next sixel row.

Request Status String (DECRQSS)

$ q pt

pt is the intermediate and/or final characters of a control function to query the status of. The terminal will send a response in the format DCS p1 $ r pt ST

p1 is 1 if the terminal supports querying the control function and 0 if it does not.

pt is the characters in the control function except the CSI characters.

Currently supported values of p1:

Value Description
m Request SGR parameters
r Request top and bottom margins
s Request left and right margins
t Request height in lines
$| Request width in columns
*| Request height in lines

Define Macro (DECDMAC)

p1 [ ; p2 [ ; p3 ] ! z

Defaults: p2 = 0 p3 = 0

Sets a macro to be replayed using CSI Pn * z

p1 is the macro number to set, and make be between 0 and 63 inclusive.

If p2 is zero, the macro numbered p1 will be deleted. If p2 is one, all macros are deleted.

If p3 is zero, the macro is defined using ASCII characters (0x20 - 0x7e and 0xa0 - 0xff only) if p3 is one, the macro is defined using hex pairs.

When the macro is defined using hex pairs, a repeat sequence may be included in the format of ! Pn ; D..D ;. Pn specifies the number of repeats (default of one instance) D..D is the sequence of pairs to send Pn times. The terminating ; may be left out if the sequence to be repeated ends at the end of the string.

Supported OSC string values

Palette Redefinition

4;(pX;pY)...

Specifies one or more palette redefinitions. pX is the palette index, and pY is the colour definition Color format: rgb:R/G/B Where R, G, and B are a sequence of one to four hex digits representing the value of the red, green, and blue channels respectively. xterm

Supported APS string values

SyncTERM implements the following APS commands:

Store File

APS SyncTERM:C;S Ps1 Ps2 ST Where Ps1 is a filename and Ps2 is the base64 encoded contents of the file. The named file is stored in the cache directory for the current connection.

List Files in Cache

APS SyncTERM:C;L Ps ST List files in cache. SyncTERM responds with an APS string with lines separated by newlines. The first line is always “SyncTERM:C;L\n” and for each matching file, a line in the form <Filename> TAB <MD5 sum> LF is sent (ie: “coolfont.fnt\t595f44fec1e92a71d3e9e77456ba80d1\n”)

And additional argument can be specified as a glob(3) pattern (defaults to “*”) in APS SyncTERM:C;L;Ps ST.

Set Font

APS SyncTERM:C;SetFont Pn Ps Where Pn is a font slot number (max 255) and Ps is a filename in the cache. This sets font slot Pn to use the specified font file.

Draw PPM

APS SyncTERM:C;DrawPPM Ps... Ps2 Draws a PPM from the cache directory on the screen. Ps2 is the filename and is required. Arguments for Ps are optional. The following options can be included (separated by semi-colons):

Option Description
SX=# Sets the left X position in the specified image to copy from. Default = 0.
SY=# Sets the top Y position in the specified image to copy from. Default = 0.
SW=# Sets the width of the portion of the image to copy. Default = Image width - SX
SH=# Sets the height of the portion of the image to copy. Default = Image height - SH
DX=# Sets the X position on the screen to draw the image at. Default = 0.
DY=# Sets the Y position on the screen to draw the image at. Default = 0.
MX=# Sets the X position in the mask to start applying from. Default = 0.
MY=# Sets the Y position in the mask to start applying from. Default = 0.
MW=# Sets the overall width of the mask (not the width to apply). If MFILE is not specified, and a mask is (ie: using MASK=), this is required. If MFILE is specified, the width is read from the file.
MH=# Sets the overall height of the mask (not the height to apply). If MFILE is not specified, and a mask is (ie: using MASK=), this is required. If MFILE is specified, the width is read from the file.
MFILE=<filename> Specifies a filename in the cache directory of a PBM file specifying a mask of which pixels to copy. Any pixel set to black (ie: 1) in the PBM will be drawn from the source image. Pixels set to white (ie: 0) will be left untouched.
MASK=<maskbits> Specifies a base64-encoded bitmap, each set bit will be drawn from the source image, cleared bits will not be drawn. Requires MW= and MH= to be specified.
MBUF Uses the loaded mask buffer.

The PPM file may be raw (preferred) or text. SyncTERM does not support more than 255 values per colour channel and assumes it is correctly using the BT.709 gamma transfer.

Load PPM

APS SyncTERM:C;LoadPPM Ps... Ps0 Loads a PPM to a buffer. Ps0 is the filename

B=# Selects the buffer (0 or 1 only) to paste from.

See Also