跳到主要内容
ansicode

DECRQUPSS / DECAUPSS —— 请求 / 指派用户首选补充字符集

查询(`CSI & u`)与指派(`DCS Ps ! u … ST`)在未触发 Locking Shift 时映射进 GR 槽位的补充字符集 —— 补完 `single-locking-shift` 留下的「谁占着 GR」一环。

字节形式

涵盖所有常见的字符串字面量写法,方便正反查找。

\\x1b[\x1b[&u request \x1bP<Ps>!u<D…D>\x1b\\ assign
\\033[\033[&u request \033P<Ps>!u<D…D>\033\\ assign
\\e[\e[&u request \eP<Ps>!u<D…D>\e\\ assign
ESC [ESC [ & u / ESC P <Ps> ! u <D…D> ESC \\
hex1b 5b 26 75 / 1b 50 <Ps> 21 75 <body> 1b 5c

说明

**DECRQUPSS**(*请求用户首选补充字符集*,`\x1b[&u`)与其设值对偶 **DECAUPSS**(*指派用户首选补充字符集*,`\x1bP<Ps>!u<body>\x1b\\`)补全 `single-locking-shift` 故意搁置的另一半 ISO 2022 字符集切换:**在任何 Locking Shift 触发之前,GR(右半 0xA0–0xFF)默认指向谁**。 **为何重要。** 在 7 位通道(Telnet、串口卡、NRCS 终端)上,GL 半段一旦让给 ASCII,GR 就是非 ASCII 字形的唯一去处。ISO 2022 把这位常驻 GR 的字符集称为*用户首选补充字符集* —— DEC 默认是 **DEC Supplemental Graphic**(历史上的重音 / 制表 / 数学集),但 ECMA-43 / DEC VT510 允许把 **ISO Latin-1**(或任何注册过的 96 字符集)装进去。DECAUPSS 让主机说「从现在起,GR 是 Latin-1」;DECRQUPSS 让主机问「GR 现在解析到哪?」。 **请求形态** —— DECRQUPSS:`\x1b[&u`。无参数;`&` 中间字节 + `u` 末字节是唯一形态。 **回复形态** —— 终端以 DECAUPSS 形帧回填当前 UPSS:`\x1bP<Ps>!u<DesignatorBytes>\x1b\\`。`Ps` = `0` 表 94 字符集(G0 风格指示符),`Ps` = `1` 表 96 字符集(Latin 风格指示符)。`<DesignatorBytes>` 是 ISO-2022 末字节,命名具体集合: - `%5` → DEC Supplemental Graphic(DEC 默认,回 `\x1bP0!u%5\x1b\\`) - `A` → ISO Latin-1 Supplemental(`\x1bP1!uA\x1b\\` —— 96 集,故 `Ps=1`) - `<` → DEC Technical Set - `=` → DEC Hebrew Supplemental、`"4` → DEC Hebrew-7、`"?` → DEC Greek、`%2` → Turkish、`R` → French、`K` → German(NRCS 家族) **设值侧** —— DECAUPSS 用相同主体。把 Latin-1 装进 GR:`\x1bP1!uA\x1b\\`。恢复 DEC 默认:`\x1bP0!u%5\x1b\\`。生效是全局的,直至下一次 DECAUPSS、DECSTR 软重置(回到 DEC 默认)或 RIS 硬重置。 **与移位家族的关系。** 指示符(`\x1b ( ` / `)` / `*` / `+`)把具体集合加载到 G0/G1/G2/G3 寄存器。Locking Shifts(LS0 / LS1 / LS1R / …)与 Single Shifts(SS2 / SS3)*调用*这些寄存器到 GL / GR。**UPSS 是回退路径** —— 当未激活任何对 GR 的 Locking Shift 时,GR 解析到 UPSS,而不是 G1。这就解释了为何 `\x1b(0`(DEC 特殊图形 → G0)+ 一字节 GL 产生制表线,但一个*高位*字节(0xA0+)在没有 LS1R 时仍击中 UPSS 当前的集合(默认 DEC Supplemental,若被改派则 Latin-1)。 **覆盖度** —— 小众。真 **xterm** + **mlterm** + **gnome-terminal** + **Konsole** = 完整(terminfo 的 `acsc`/`smacs`/`rmacs` 仍经此路径,故 ISO 2022 在其中仍活)。**WezTerm** + **iTerm2** = 部分(解析并确认请求但视主体为空操作 —— 默认就是 Latin-1,因为 UTF-8 已覆盖了 UPSS 的全部用途)。**Kitty** / **Alacritty** / **Ghostty** / **Windows Terminal** / **cmd / ConPTY** / **macOS Terminal** / **Linux console** = 无作用(两向均静默忽略 —— UTF-8 已废止该用例)。2026 年,仅当接收端是已知 ISO-2022-aware 模拟器时再发 DECAUPSS;其余场景直接用 UTF-8 编码文本。

规范出处: DEC VT510 RM (DECRQUPSS / DECAUPSS) / ISO 2022 §6.4 (UPSS) / ECMA-35 §13.4

参数

Ps = 0 (94-set)指示符是 94 字符集(多数 DEC 集 —— DEC Supplemental %5、DEC Technical <、NRCS R/K/=)
Ps = 1 (96-set)指示符是 96 字符集(Latin-1 A、Latin-2 B、Latin-Cyrillic L、Latin-Greek F、Latin-Hebrew H)
%5DEC 补充图形(UPSS 的 DEC 默认)
AISO Latin-1 补充(脱离 DEC 模式后的现代默认)
<DEC 技术字符集(技术排版的数学 / 希腊字形)

示例

bash
# Probe UPSS, parse the DCS reply (timeout-protected).\nprintf '\\033[&u'\nIFS= read -rs -d '\\\\' -t 0.1 reply </dev/tty 2>/dev/null\necho \"UPSS reply: ${reply}\"   # xterm: \\x1bP1!uA\\x1b  (Latin-1 today on most builds)\n# Re-assign UPSS to DEC Supplemental Graphic (DEC default):\nprintf '\\033P0!u%%5\\033\\\\'
python
import sys, re, tty, termios, select\n# Switch GR to ISO Latin-1, then back to DEC Supplemental.\nsys.stdout.write('\\x1bP1!uA\\x1b\\\\')   # GR = Latin-1\nsys.stdout.flush()\n# ... do work that emits 0xA0–0xFF bytes ...\nsys.stdout.write('\\x1bP0!u%5\\x1b\\\\')  # restore DEC default\nsys.stdout.flush()
go
// Parse a DECRQUPSS reply: extract Ps + designator.\nimport (\n    \"fmt\"\n    \"regexp\"\n)\nvar upssRe = regexp.MustCompile(\"\\x1bP([01])!u([^\\x1b]+)\\x1b\\\\\\\\\")\nfunc parseUPSS(buf string) (ps int, designator string, ok bool) {\n    m := upssRe.FindStringSubmatch(buf)\n    if m == nil { return 0, \"\", false }\n    fmt.Sscanf(m[1], \"%d\", &ps)\n    return ps, m[2], true\n}
javascript
// Reassign UPSS to Latin-1 (modern default) and confirm.\nprocess.stdout.write('\\x1bP1!uA\\x1b\\\\');\n// Query: emit DECRQUPSS and parse the reply.\nprocess.stdout.write('\\x1b[&u');\nprocess.stdin.once('data', (buf) => {\n  const m = /\\x1bP([01])!u([^\\x1b]+)\\x1b\\\\/.exec(buf.toString('binary'));\n  console.error('UPSS Ps=' + (m?.[1] ?? '?') + ' set=' + (m?.[2] ?? '?'));\n});
c
/* Set UPSS to Latin-1, then probe. */\nfputs(\"\\x1bP1!uA\\x1b\\\\\", stdout);\nfputs(\"\\x1b[&u\", stdout); fflush(stdout);\n/* Read until ST (0x1b 0x5c) with 100ms select timeout, then parse !u<designator>. */

终端支持

xterm
支持
Linux console (fbcon)
不支持
macOS Terminal.app
不支持
iTerm2
部分
Windows Terminal
不支持
cmd.exe / ConPTY
不支持
kitty
不支持
alacritty
不支持
WezTerm
部分
Ghostty
不支持
GNOME Terminal
支持
Konsole
支持
tmux
不支持
GNU screen
不支持

相关序列

在家族食谱中

DCS 食谱 · 3. 向终端提问 —— DECRQSS、terminfo cap、DECRQTSR、DECRQUPSS、光标样式