^[control-codes live in libghostty-vt

Control sequences

SPD Select Presentation Directions

ECMA-48's choice of line orientation, line progression and character path for the whole presentation, which terminals that handle bidirectional text take as left to right or right to left.

CSI Ps1 ; Ps2 SP S
Defaults
Ps1 = 0, Ps2 = 0
ECMA-48
§8.3.130 SPD – Select Presentation Directions, p. 66
Specification
BiDi in Terminal Emulators, v0.1, The escape sequences

In ECMA-48, SPD sets three things at once for the whole presentation: the line orientation, horizontal or vertical; the line progression, which way successive lines follow one another; and the character path, which way text runs along a line. Ps1 picks one of eight combinations, and Ps2 says what happens to text already there, as it does for SCP. Both default to 0.

Ps1LinesLine progressionCharacter path
0horizontaltop to bottomleft to right
1verticalright to lefttop to bottom
2verticalleft to righttop to bottom
3horizontaltop to bottomright to left
4verticalleft to rightbottom to top
5horizontalbottom to topright to left
6horizontalbottom to topleft to right
7verticalright to leftbottom to top
Ps2Effect on text already there
0left to the implementation
1the presentation is updated to match the data
2the data is updated to match the presentation

BiDi in Terminal Emulators reads SPD and SCP as setting the same character path, the last one received winning, and picks SCP for programs to use: the line orientation and progression can only be global, while a character path can belong to a paragraph, and SPD would also apply at once to everything on the screen. Programs written to the recommendation do not send SPD. A terminal may still take it from an older program, and the recommendation suggests SPD 0 and 3, the two horizontal, top-to-bottom layouts, as other ways of writing SCP 1 and SCP 2. It considers and rejects SPD as a way to set the direction of a whole full-screen canvas, since BDSM and autodetection would need a whole-screen form of their own too.

VTE does just that: 0 or a missing parameter is left to right, 3 is right to left, and every other value is ignored, as is Ps2. Like SCP, it applies to the paragraph the cursor is in only if the cursor is at its start. mintty documents the same two values, and calls SPD “a deprecated fun feature” (documentation).

A default xterm ignores CSI SP S: its table for a CSI with a space intermediate has nothing for S (csi_sp_table). libghostty-vt ignores it too. The intermediate is the whole difference between SPD and SU, CSI Pn S, and neither terminal scrolls. The cases follow xterm.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984Nonot in the manual
VT510manual, 1st ed., 1993Nonot in the manual
xtermpatch 412, xterm-411aNoignored; CSI SP S is not in its parser
libghostty-vt919dca5Noignored
ConEmubuild 230724, its documentationNonot in its ANSI escape codes
mintty3.8.3, its documentationPartly0 and 3 only, for left to right and right to left (documentation)
VTE0.84.1, sourcePartly0 and 3 only, as the BiDi recommendation suggests (source)

Validation

SPD-1: Ignored, with nothing printed

AB
\e[3 S
C
|ABC___|
cursor 1,4

SPD-2: It is not SU, and does not scroll

ABC\r\n
DEF
\e[ S
\e[3;0 S
|ABC___|
|DEF___|
|______|
cursor 2,4

SPD-3: Nor does a vertical presentation turn the screen

AB\r\n
CD
\e[1 S
\e[7;1 S
|AB____|
|CD____|
cursor 2,3
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.