hterm Control Sequences

Like every terminal out there, hterm supports a number of standard (and perhaps not so standard) control/escape sequences. This doc outlines hterm's position on everything -- things that are supported, things that will never be supported, etc...

It's not meant to be a comprehensive guide to a terminal. For that, please see the References section.

Parsing of these sequences are contained entirely in hterm_vt.js, and the character maps are defined in hterm_vt_character_map.js.

For TBD entries, it means we haven‘t put in the work to implement the feature yet, but we generally wouldn’t be adverse to adding it. Or we haven‘t quite figured out how best to do so. Or we just haven’t thought about it at all to say no :).

Similarly for entries marked as passed thru -- we might do something with them in the future, but currently we just print it.

However, for entries marked “won't support”, it means we don't consider them relevant and will probably never be implemented.

If you come across missing features or have other requests, feel free to file a bug at https://goo.gl/vb94JY.

General Guidelines

We aim to be compliant with:

  • ECMA-35 (Character Code Structure and Extension Techniques): covers some fundamentals related to character sets, the notions of C0, C1, G0, etc... (but not their contents), and how escape sequences work (but not what they mean).
  • ECMA-43 (8-bit Coded Character Set Structure and Rules): Builds on top of ECMA-35 by defining the character sets (e.g. 0x40 == @).
  • ECMA-48 (Control Functions for Coded Character Sets): Builds on top of ECMA-35 by defining many of the common escape sequences. Supersedes the ANSI codes, and is equivalent to ISO/IEC 6429.

Going beyond those basics, we use these sites for guidance:

  • XTerm: Canonical terminal emulator in the X world.
  • VT100.net: Spec sheets for VT100 and similar terminals.

C0 Control Codes

These are the basic characters in the 0x00 - 0x1F range.

While DEL (0x7F) isn't actually part of C0, we list it here for convenience.

SeqDecHexNameCDescriptionAction
^@0000NUL\0NullIgnored
^A0101SOHStart of HeadingPassed thru
^B0202STXStart of TextPassed thru
^C0303ETXEnd of TextPassed thru
^D0404EOTEnd of TransmissionPassed thru
^E0505ENQEnquiryIgnored
^F0606ACKAcknowledgePassed thru
^G0707BEL\aBellSupported
^H0808BS\bBackspaceSupported
^I0909HT\tCharacter Tabulation (Horizontal Tabulation)Supported
^J100ALF\nLine FeedSupported
^K110BVT\vLine Tabulation (Vertical Tabulation)Converted to LF (\n)
^L120CFF\fForm FeedConverted to LF (\n)
^M130DCR\rCarriage ReturnSupported
^N140ESO/LS1Shift Out / Locking Shift OnePoint GL to G1
^O150FSI/LS0Shift In / Locking Shift ZeroPoint GL to G0
^P1610DLEData Link EscapePassed thru
^Q1711DC1Device Control One (XON)Ignored (TBD)
^R1812DC2Device Control TwoPassed thru
^S1913DC3Device Control Three (XOFF)Ignored (TBD)
^T2014DC4Device Control FourPassed thru
^U2115NAKNegative AcknowledgePassed thru
^V2216SYNSynchronous IdlePassed thru
^W2317ETBEnd of Transmission BlockPassed thru
^X2418CANCancelSupported (1)
^Y2519EMEnd of mediumPassed thru
^Z261ASUBSubstituteConverted to CAN
^[271BESC\eEscapeSupported (2)
^\281CFS/IS4File Separator / Information Separator FourPassed thru
^]291DGS/IS3Group Separator / Information Separator ThreePassed thru
^^301ERS/IS2Record Separator / Information Separator TwoPassed thru
^_311FUS/IS1Unit Separator / Information Separator OnePassed thru
^?1277FDELDeleteSupported

  1. Used to cancel escape sequences, and to change GL back to G0.
  2. ESC is a multiplexed command; see section below for more details.

C1 Control Codes

These are some extended characters in the 0x80 - 0x9F range.

Since these don‘t play well with UTF-8 encoding, they’re typically accessed via an escape sequence. e.g. ESC+@ (0x1b 0x40) instead of 0x80.

ESCDecHexNameDescriptionAction
@12880PADPadding CharacterIgnored (TBD)
A12981HOPHigh Octet PresetIgnored (TBD)
B13082BPHBreak Permitted HereIgnored (TBD)
C13183NBHNo Break HereIgnored (TBD)
D13284INDIndexLike newline, but keep column position
E13385NELNext LineLike newline, but doesn't add a line
F13486SSAStart of Selected AreaWon't support
G13587ESAEnd of Selected AreaIgnored (TBD)
H13688HTSCharacter Tabulation SetSets horizontal tab stop at the column
I13789HTJCharacter Tabulation With JustificationIgnored (TBD)
J1388AVTSLine Tabulation SetIgnored (TBD)
K1398BPLDPartial Line ForwardIgnored (TBD)
L1408CPLUPartial Line BackwardIgnored (TBD)
M1418DRIReverse Line FeedMove up one line keeping column position
N1428ESS2Single-Shift TwoIgnored
O1438FSS3Single-Shift ThreeIgnored
P14490DCSDevice Control StringIgnored (TBD) (1)
Q14591PU1Private Use OneIgnored (TBD)
R14692PU2Private Use TwoIgnored (TBD)
S14793STSSet Transmit StateIgnored (TBD)
T14894CCHCancel characterIgnored (TBD)
U14995MWMessage WaitingIgnored (TBD)
V15096SPAStart of Guarded AreaWon't support
W15197EPAEnd of Guarded AreaWon't support
X15298SOSStart of StringWon't support
Y15399SGCISingle Graphic Character IntroducerIgnored (TBD)
Z1549ASCISingle Character IntroducerSends [?1;2c
[1559BCSIControl Sequence IntroducerSupported (2)
\1569CSTString TerminatorUsed to terminate escape sequences
]1579DOSCOperating System CommandSupported (3)
^1589EPMPrivacy MessageWon't support
_1599FAPCApplication Program CommandWon't support

  1. DCS is a multiplexed command; see section below for more details.
  2. CSI is a multiplexed command; see section below for more details.
  3. OSC is a multiplexed command; see section below for more details.

G0/G1/G2/G3 Graphic Codesets for GL/GR (SCS)

With the rise of UTF-8 encoding, graphic codesets have fallen out of favor. Although we still support a limited number for legacy systems.

Basically, instead of seeing things like “w” or “#”, you'll see “┬” or “£”. These were used to get basic graphics (like border lines), or to support other 7-bit character sets (like German characters ß and ü).

The terminal has 4 graphic codeset slots (named G0, G1, G2, and G3), and 2 pointers (GL and GR) to those slots. The active display then uses those pointers to determine what is shown. Both the slots and pointers can be updated at any time.

The GR pointer, while tracked, does not actually get processed. When running in a UTF8 environment, it's easy to corrupt codeunits in a codepoint leading to bad output.

We don't currently differentiate between 94-character sets and 96-character sets. Although all of the maps we support are within the 94-char range.

As for the character sets that you can actually load, we support some hard character sets, but not all of them. We do not support soft character sets.

Here's the list of national replacement character sets (NRCS) we support:

IDDescription
0Graphics
4Dutch
5Finnish
6Norwegian/Danish
7Swedish
=Swiss
ABritish
BUnited States (ASCII)
CFinnish (same as “5” above)
ENorwegian/Danish (same as “6” above)
HSwedish (same as “7” above)
KGerman
QFrench Canadian
RFrench
YItalian
ZSpanish

Escape Sequences

These are other escape sequences we support. This is similar to the C1 Control Codes space, but there is only a two byte sequence. e.g. ESC+# (0x1b 0x23).

Some of these may have subcommands, so it might end up being a three byte sequence where the 3rd byte is further interpreted. We refer to that as arg1 in the Action column below.

ESCNameDescriptionAction
SPIgnored (TBD)
"Ignored (TBD)
#DECSemi-supported
$Ignored (TBD)
%Character set controlIgnored (TBD)
&Ignored (TBD)
`Ignored (TBD)
(SCSSet G0 character set (VT100)Set G0 to NRCS arg1
)SCSSet G1 character set (VT220)Set G1 to NRCS arg1
*SCSSet G2 character set (VT220)Set G2 to NRCS arg1
+SCSSet G3 character set (VT220)Set G3 to NRCS arg1
-SCSSet G1 character set (VT300)Set G1 to NRCS arg1
.SCSSet G2 character set (VT300)Set G2 to NRCS arg1
/SCSSet G3 character set (VT300)Set G3 to NRCS arg1
0Ignored (TBD)
1Ignored (TBD)
2Ignored (TBD)
3Ignored (TBD)
4Ignored (TBD)
5Ignored (TBD)
6DECBIBack IndexIgnored (TBD)
7DECSCSave CursorSupported
8DECRCRestore CursorSupported
9DECFIForward IndexIgnored (TBD)
:Ignored (TBD)
;Ignored (TBD)
<Ignored (TBD)
=DECKPAMKeypad Application ModeSupported
>DECKPNMKeypad Numeric ModeSupported
?Ignored (TBD)
[Ignored (TBD)
\Ignored (TBD)
]Ignored (TBD)
^Ignored (TBD)
_Ignored (TBD)
`DMIDisable Manual InputIgnored (TBD)
aINTInterruptIgnored (TBD)
bEMIEnable Manual InputIgnored (TBD)
cRISReset to Initial StateResets terminal state
dCMDCoding Method DelimiterIgnored (TBD)
eIgnored (TBD)
fIgnored (TBD)
gIgnored (TBD)
hIgnored (TBD)
iIgnored (TBD)
jIgnored (TBD)
kIgnored (TBD)
lMemory lock/unlockWon't support
mMemory lock/unlockWon't support
nLS2Locking Shift TwoPoint GL to G2
oLS3Locking Shift ThreePoint GL to G3
pIgnored (TBD)
qIgnored (TBD)
rIgnored (TBD)
sIgnored (TBD)
tIgnored (TBD)
uIgnored (TBD)
vIgnored (TBD)
wIgnored (TBD)
xIgnored (TBD)
yIgnored (TBD)
zIgnored (TBD)
{Ignored (TBD)
|LS3RLocking Shift Three RightIgnored (Point GR to G3)
}LS2RLocking Shift Two RightIgnored (Point GR to G2)
~LS1RLocking Shift One RightIgnored (Point GR to G1)

ESC+# (DEC)

A few random escape sequences. They are initiated with ESC+]+#.

DSCNameDescriptionAction
3DECDHLDouble-Width, Double-Height Line (Top Half)Ignored
4DECDHLDouble-Width, Double-Height Line (Bottom Half)Ignored
5DECSWLSingle-Width, Single-Height LineIgnored
6DECDWLDouble-Width, Single-Height LineIgnored
8DECALNScreen Alignment PatternFill terminal with E's

Device Control String (DCS)

Device Control String is not currently supported which means none of its subcommands work either (like ReGIS or Sixel).

Operating System Command (OSC)

This is a grab bag of various escape sequences. They are initiated with ESC+]. Arguments to the sequences are typically delimited by ;, and terminated with BEL. e.g. ESC+] 0 ; title BEL (0x1b 0x5d 0x30 0x3b ... 0x07).

For example:

OSCDescriptionStatusFormat
0Set window titleOnly window titleESC ] 0 ; [title] \a
2Set window titleConverted to 0
4Set/read color paletteSupportedESC ] 4 ; index1;rgb1;...;indexN;rgbN \a
9iTerm2 Growl notificationsSupportedESC ] 9 ; [message] \a
10Set foreground colorSupportedESC ] 10 ; [X11 color spec] \a
11Set background colorSupportedESC ] 11 ; [X11 color spec] \a
50Set the cursor shapeSupportedESC ] 50 ; CursorShape=[0|1|2] \a
52Clipboard operationsOnly “c” supportedESC ] 52 ; c ; [base64 data] \a
777rxvt-unicode (urxvt) modulesOnly “notify” supportedESC ] 777 ; notify ; [title] ; [body] \a

Control Sequence Introducer (CSI)

These are various color and cursor related escape sequences. Also referred to as ANSI escape sequences. They are initiated with ESC+[. Arguments to the sequences are typically delimited by ; and precede the command. e.g. ESC+[ arg1 ; arg2 ; argN m.

CSINameDescriptionAction
@ICHInsert Blank CharactersAdd space
ACUUCursor UpMove cursor up arg1 rows
BCUDCursor DownMove cursor down arg1 rows
CCUFCursor ForwardMove cursor forward arg1 columns
DCUBCursor BackwardMove cursor back arg1 columns
ECNLCursor Next LineMove cursor down arg1 rows and to first column
FCPLCursor Preceding LineMove cursor up arg1 rows and to first column
GCHACursor Character AbsoluteMove cursor to arg1 column
HCUPCursor PositionMove cursor to arg1 row and arg2 column
ICHTCursor Forward TabulationMove cursor forward arg1 tabs
JEDErase in Display!arg1 or arg1 == 0: Clear cursor to end of display
arg1 == 1: Clear start of display to cursor
arg1 == 2: Clear display
?JDECSEDSelective Erase in DisplaySame as ED above
KELErase in Line!arg1 or arg1 == 0: Clear cursor to end of line
arg1 == 1: Clear start of line to cursor
arg1 == 2: Clear line
?KDECSELSelective Erase in LineSame as EL above
LILInsert LinesInsert arg1 lines
MDLDelete LinesDelete arg1 lines
NEFErase in FieldIgnored (TBD)
OEAErase in AreaIgnored (TBD)
PDCHDelete CharactersDelete arg1 characters before cursor
QSEESelect Editing ExtentIgnored (TBD)
RCPRActive Position ReportIgnored (TBD)
SSUScroll UpScroll up arg1 lines
TSDScroll DownScroll down arg1 lines
>TWon't support
UNPNext PageIgnored (TBD)
VPPPrevious PageIgnored (TBD)
WCTCCursor Tabulation ControlIgnored (TBD)
XECHErase CharactersDelete arg1 characters after cursor
YCVTCursor Line TabulationIgnored (TBD)
ZCBTCursor Backward TabulationMove cursor back arg1 tabs
[SRSStart Reversed StringIgnored (TBD)
\PTXParallel TextsIgnored (TBD)
]SDSStart Directed StringIgnored (TBD)
^SIMDSelect Implicit Movement DirectionIgnored (TBD)
_Ignored (TBD)
`HPACharacter Position AbsoluteSame as CHA above
aHPRCharacter Position RelativeMove cursor forward arg1 columns
bREPRepeatIgnored (TBD)
cDA/DA1Send Primary Device AttributesCurrently reports “VT100 with Advanced Video Option”
>cDA2Send Secondary Device AttributesCurrently reports “VT100”
dVPALine Position AbsoluteMove cursor to arg1 row
eVPRLine Position ForwardIgnored (TBD)
fHVPHorizontal and Vertical PositionSame as CUP above
gTBCTab Clear!arg1 or arg1 == 0: Clear tab stop at cursor
arg1 == 3: Clear all tab stops
hSMSet ModeSupported (1)
?hDECSETDEC Set ModeSupported (2)
iMCMedia CopyWon't support
?iDECMCDEC Media CopyWon't support
jHPBCharacter Position BackwardIgnored (TBD)
kVPBLine Position BackwardIgnored (TBD)
lRMReset ModeSupported (1)
?lDECRSTDEC Mode ResetSupported (2)
mSGRSelect Graphic RenditionSupported (3)
>mxterm specific keyboard modesWon't support
nDSRDevice Status ReportsSupported
?nDECDSRDEC Device Status ReportsSupported
>nxterm specific modifiersWon't support
oDAQDefine Area QualificationIgnored (TBD)
pIgnored (TBD)
>pxterm specific cursor display controlIgnored (TBD)
!pDECSTRSoft Terminal ResetSupported
$pDECRQMRequest Mode - Host To TerminalIgnored (TBD)
?$pDECRQMRequest Mode - Host To TerminalIgnored (TBD)
"pDECSCLSelect Conformance LevelIgnored (TBD)
qDECLLLoad LEDsIgnored (TBD)
␠qDECSCUSRSet Cursor StyleSupported
"qDECSCASelect Character Protection AttributeWon't support
rDECSTBMSet Top and Bottom MarginsSupported
?rWon't support
$rWon't support
sSave cursor (ANSI.SYS)Supported
?sWon't support
tWon't support
$tDECRARAReverse Attributes in Rectangular AreaWon't support
>tWon't support
␠tDECSWBVSet Warning Bell VolumeWon't support
uRestore cursor (ANSI.SYS)Supported
␠uDECSMBVSet Margin Bell VolumeWon't support
vIgnored (TBD)
$vDECCRACopy Rectangular AreaWon't support
wIgnored (TBD)
'wDECEFRWon't support
xDECREQTPARMIgnored (TBD)
*xDECSACESelect Attribute Change ExtentWon't support
$xDECFRAFill Rectangular AreaWon't support
yIgnored (TBD)
zIgnored (TBD)
'zIgnored (TBD)
$zDECERAErase Rectangular AreaWon't support
'{Ignored (TBD)
'|Ignored (TBD)
'}DECICInsert ColumnWon't support
'~DECDCDelete ColumnWon't support

  1. SM/RM are multiplexed commands; see section below for more details.
  2. DECSET/DECRST are multiplexed commands; see section below for more details.
  3. SGR is a multiplexed command; see section below for more details.

Modes (SM) / (RM)

Ignoring the use of the generic word “mode”, the Set Mode and Reset Mode commands are used to control different operating modes. Historically these made sense with a wide range of hardware devices that used different binary protocols, but nowadays we can ignore most as dead code. That is why hterm doesn't support most of these.

For SM, the specified mode is enabled. For RM, it's disabled (reset).

ModeNameDescriptionAction
1GATMGuarded Area Transfer ModeWon't support
2KAMKeyboard Action ModeWon't support
3CRMControl Representation ModeIgnored
4IRMInsertion Replacement ModeSupported
5SRTMStatus Report Transfer ModeIgnored
6ERMERasure modeIgnored
7VEMLine Editing ModeIgnored
8BDSMBi-Directional Support ModeIgnored
9DCSMDevice Component Select ModeIgnored
10HEMCharacter Editing ModeIgnored
11PUMPositioning Unit ModeIgnored
12SRMSend/Receive ModeWon't support
13FEAMFormat Effector Action ModeIgnored
14FETMFormat Effector Transfer ModeIgnored
15MATMMultiple Area Transfer ModeIgnored
16TTMTransfer Termination ModeIgnored
17SATMSelected Area Transfer ModeIgnored
18TSMTabulation Stop ModeIgnored
19ReservedIgnored
20LNMAutomatic NewlineSupported
21GRCMGraphic Rendition Combination ModeIgnored
22ZDMZero Default ModeIgnored

Private Modes (DECSET) / (DECRST)

Similar to the SM & RM commands, these are extensions that DEC added to their VT's. Then other people started adding their own. There are many, and we support some of them.

ModeNameSourceDescriptionStatus
1DECCKMDECApplication Cursor KeysSupported
2DECANMDECDesignate USASCII for character sets G0-G3, and set VT100 modeIgnored (TBD)
3DECCOLMDEC132 Column ModeSupported
4DECSCLMDECSmooth (Slow) ScrollWon't support
5DECSCNMDECReverse VideoSupported
6DECOMDECOrigin ModeSupported
7DECAWMDECWraparound ModeSupported
8DECARMDECAuto-repeat KeysWon't support
9Send Mouse X & Y on button pressIgnored (TBD)
10rxvtShow toolbarWon't support
12att610Start blinking cursorSupported
18DECPFFDECPrint form feedIgnored (TBD)
19DECPEXDECSet print extent to full screenWon't support
25DECTCEMDECShow CursorSupported
30rxvtShow scrollbarSupported
35rxvtEnable font-shifting functionsWon't support
38DECTEKDECEnter Tektronix ModeWon't support
40Allow 80 - 132 (DECCOLM) ModeSupported
41cursesmore(1) fixIgnored (TBD)
42DECNRCMDECEnable Nation Replacement Character setsIgnored (TBD)
44Turn On Margin BellIgnored (TBD)
45Reverse-wraparound ModeSupported
46Start LoggingIgnored (TBD)
47Use Alternate Screen BufferSupported
66DECNKMDECApplication keypadIgnored (TBD)
67DECBKMDECBackarrow key sends backspaceSupported
1000MOUSE_REPORT_CLICKSend Mouse X & Y on button press and releaseSupported
1001Use Hilite Mouse TrackingIgnored (TBD)
1002MOUSE_REPORT_DRAGUse Cell Motion Mouse TrackingSupported
1003Use All Motion Mouse TrackingIgnored (TBD)
1004Send FocusIn/FocusOut eventsIgnored (TBD)
1005Enable Extended Mouse ModeIgnored (TBD)
1010rxvtScroll to bottom on tty outputSupported
1011rxvtScroll to bottom on key pressSupported
1034Interpret “meta” key, sets eighth bitWon't support
1035Enable special modifiers for Alt and NumLock keysWon't support
1036Send ESC when Meta modifies a keySupported
1037Send DEL from the editing-keypad Delete keyIgnored (TBD)
1039Send ESC when Alt modifies a keySupported
1040Keep selection even if not highlightedWon't support
1041Use the CLIPBOARD selectionWon't support
1042Enable Urgency window manager hint when Control-G is receivedIgnored (TBD)
1043Enable raising of the window when Control-G is receivedIgnored (TBD)
1047Use Alternate Screen BufferSupported
1048Save cursor as in DECSCSupported
1049Combine 1047 and 1048 modes and clearSupported
1050Set terminfo/termcap function-key modeIgnored (TBD)
1051Set Sun function-key modeWon't support
1052Set HP function-key modeWon't support
1053Set SCO function-key modeWon't support
1060Set legacy keyboard emulation (X11R6)Won't support
1061Set VT220 keyboard emulationIgnored (TBD)
2004Set bracketed paste modeSupported

Select Graphic Rendition (SGR)

These are various color and cursor related escape sequences. Also referred to as ANSI escape sequences. They are initiated with ESC+[ and finish with the m command. Accepts an arbitrary number of args delimited by ; and in any order.

SGRCharacter AttributeAction
Enable Attributes
0Normal (default)Supported
1BoldSupported
2FaintSupported
3ItalicSupported
4UnderlinedSupported
5BlinkSupported
6Rapid blinkIgnored (TBD)
7InverseSupported
8InvisibleSupported
9Crossed outSupported
Disable Attributes
21Double underlinedIgnored (TBD)
22Normal (decorations)Supported
23Not italicSupported
24Not underlinedSupported
25Steady (not blink)Supported
26ReservedIgnored (TBD)
27Positive (not inverse)Supported
28Visible (not invisible)Supported
29Not crossed outSupported
Foreground Color
30Set foreground color to BlackSupported
31Set foreground color to RedSupported
32Set foreground color to GreenSupported
33Set foreground color to YellowSupported
34Set foreground color to BlueSupported
35Set foreground color to MagentaSupported
36Set foreground color to CyanSupported
37Set foreground color to WhiteSupported
38Set foreground color to 8-bit/24-bit colorSupported (1)
39Set foreground color to default (original)Supported
Background Color
40Set background color to BlackSupported
41Set background color to RedSupported
42Set background color to GreenSupported
43Set background color to YellowSupported
44Set background color to BlueSupported
45Set background color to MagentaSupported
46Set background color to CyanSupported
47Set background color to WhiteSupported
48Set background color to 8-bit/24-bit colorSupported (1)
49Set background color to default (original)Supported
Misc
50Reserved for canceling SGR 26Ignored (TBD)
51FramedIgnored (TBD)
52EncircledIgnored (TBD)
53OverlinedIgnored (TBD)
54Not framed and not encircledIgnored (TBD)
55Not overlinedIgnored (TBD)
56ReservedIgnored (TBD)
57ReservedIgnored (TBD)
58ReservedIgnored (TBD)
59ReservedIgnored (TBD)
60Ideogram underline or right side lineIgnored (TBD)
61Ideogram double underline or double right side lineIgnored (TBD)
62Ideogram overline or left side lineIgnored (TBD)
63Ideogram double overline or double left side lineIgnored (TBD)
64Ideogram stress markingIgnored (TBD)
65Cancel SGR 60 through 64Ignored (TBD)
Bright Foreground Color
90Set foreground color to bright BlackSupported
91Set foreground color to bright RedSupported
92Set foreground color to bright GreenSupported
93Set foreground color to bright YellowSupported
94Set foreground color to bright BlueSupported
95Set foreground color to bright MagentaSupported
96Set foreground color to bright CyanSupported
97Set foreground color to bright WhiteSupported
Bright Background Color
100Set background color to bright BlackSupported
101Set background color to bright RedSupported
102Set background color to bright GreenSupported
103Set background color to bright YellowSupported
104Set background color to bright BlueSupported
105Set background color to bright MagentaSupported
106Set background color to bright CyanSupported
107Set background color to bright WhiteSupported

For 88- or 256-color support, the following apply:

  • 38 ; 5 ; P -- Set foreground color to P.
  • 48 ; 5 ; P -- Set background color to P.

For true color (24-bit) support, the following apply.

  • 38 ; 2 ; R ; G ; B -- Set foreground color to rgb(R, G, B)
  • 48 ; 2 ; R ; G ; B -- Set background color to rgb(R, G, B)

Note that most terminals consider “bold” to be “bold and bright”. In some documents the bold state is even referred to as bright. We interpret bold as bold-bright here too, but only when the “bold” setting comes before the color selection.

References