Skip to main content

XTGETTCAP

AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Experimental

XTGETTCAP (XTerm Get Termcap/Terminfo) is a DCS sequence that queries the terminal for the value of termcap or terminfo capabilities by name. Capability names are hex-encoded in the request, and the terminal responds with the corresponding value.

Syntax​

DCS + q hex-name ST              XTGETTCAP request
DCS Ps + r hex-name = value ST XTGETTCAP response
Formal syntax
(* Request — one or more hex-encoded capability names, separated by ";" *)
XTGETTCAP-request  = 0x1b, "P", "+", "q", hex-name, { ";", hex-name }, 0x1b, "\\" ;
hex-name = hex-pair, { hex-pair } ;
hex-pair = hex-digit, hex-digit ;

(* Response — one per requested name *)
XTGETTCAP-response = 0x1b, "P", Ps, "+", "r", hex-name, [ "=", hex-value ], 0x1b, "\\" ;
Ps = "0" | "1" ;                     (* 0 = invalid/unknown, 1 = valid *)
hex-value = hex-pair, { hex-pair } ;
hex-digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"
        | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f"
        | "A" | "B" | "C" | "D" | "E" | "F" ;

Parameters​

ParameterDescription
hex-name (request)The termcap/terminfo capability name, hex-encoded (each ASCII byte as two hex digits)
Ps (response)1 if the capability is known, 0 if not recognized
hex-value (response)The capability value, hex-encoded

Response​

The terminal sends one response per queried capability name. If the capability is recognized, Ps = 1 and the value follows after =. If not recognized, Ps = 0 and no value is included.

Multiple capabilities can be queried in a single request by separating the hex-encoded names with ;. The terminal may respond with multiple DCS responses or a single combined response depending on the implementation.

Description​

XTGETTCAP was introduced in XTerm (patch 253) to allow applications to query termcap and terminfo capabilities directly from the terminal, rather than relying on the system's terminfo database. This is particularly useful in environments where the terminfo entry may be missing, outdated, or incorrect.

Capability names must be hex-encoded before sending. For example, to query the TN (terminal name) capability, you encode TN as 544E (0x54 = T, 0x4E = N).

Common capability names​

CapabilityHex encodingDescription
TN544ETerminal name
Co436FMaximum number of colors
RGB524742Direct color support
cols636F6C73Number of columns
lines6C696E6573Number of lines

XTerm-specific extensions​

Some terminals extend XTGETTCAP to support querying non-standard capabilities. For example, Kitty and foot use it to report capabilities like RGB for direct color support. The allowTcapOps resource in XTerm must be enabled for this feature to function.

Encoding example​

To query the Co (colors) capability:

  1. Encode Co as hex: C = 0x43, o = 0x6F, giving 436F
  2. Send: DCS + q 436F ST
  3. Receive: DCS 1 + r 436F = 323536 ST (value 256 hex-encoded)

Examples​

# Query terminal name (TN = 0x54 0x4E)
printf '\eP+q544E\e\\'

# Query max colors (Co = 0x43 0x6F)
printf '\eP+q436F\e\\'

# Query RGB support (RGB = 0x52 0x47 0x42)
printf '\eP+q524742\e\\'

# Query multiple capabilities in one request
printf '\eP+q544E;436F;524742\e\\'

Specifications​

SpecificationSection
XTerm ctlseqs—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✗No
Bobcat??Bobcat is built on TerminalCtrl library which handles all escape sequence parsing. No evidence found in Bobcat's code, but this may be implemented in the external TerminalCtrl dependency.
contour✓v0.1.0XTGETTCAP (DCS + q - Terminal capability query) implemented in Functions.h line 625 and handled via hookXTGETTCAP in Screen.cpp line 4063
foot✓1.11.0Builtin terminfo capability queries
Ghostty✓v1.0.0Terminal capability query
iTerm2✓YesDCS + q termcap query via DCS_REQUEST_TERMCAP_TERMINFO token
Kitty✓YesDCS + q implementation
Konsole✗No
mintty✓YesXTGETTCAP (DCS + q) detected in src/child.c:378 but specific handler details not fully traced
mlterm✓3.4.2
PuTTY✗NoNo XTGETTCAP (DCS + q) implementation found
Rio✓v0.2.20Only one capability per request is supported
rxvt-unicode✗NoDCS sequences explicitly not implemented (discarded)
st✗NoDCS sequences are not handled
terminology✗NoRecognized but marked as unhandled TODO
VT100✗No
VTE✗No
WezTerm✓YesDCS + q terminal capability query
Windows Terminal✗No
xterm✓xterm-253DCS + q - Terminal capability query (XTGETTCAP). Requires allowTcapOps resource
xterm.js✗NoExplicitly marked as unsupported
Multiplexers
cy✗NoDCS not implemented
GNU Screen✗No
tmux✗No
tuios✗No
Zellij✗NoNo XTGETTCAP (DCS + q) support found

See also​