跳到主要内容
ansicode

DECCOLM — 80 / 132 列模式(CSI ? 3 h / l)

在 80 列与 132 列页宽间切换 —— DEC VT100 旗舰「宽模式」开关,现代模拟器普遍以资源开关默认禁用。

字节形式

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

\\x1b[\x1b[?3h (132 cols) \x1b[?3l (80 cols)
\\033[\033[?3h / \033[?3l
\\e[\e[?3h / \e[?3l
ESC [ESC [ ? 3 h / ESC [ ? 3 l
hex1b 5b 3f 33 68 / 6c

说明

Column Mode(DECCOLM,私有模式 3)。设置(`\x1b[?3h`)请求 132 列页宽;重置(`\x1b[?3l`,多数默认)回到 80 列。最初是 DEC VT100 的硬件特性 —— 切换该模式触发真实的字体 / 时钟切换,物理缩小每个字符单元以在同一 CRT 上容纳 132 个字形。软件模拟器以重设页面缓冲实现;副作用与 DECSCPP 相同且属设计意图: - 屏幕**清空**为当前 SGR 背景色。 - 光标**归位**到(1, 1)。 - **DECSTBM 与 DECSLRM 重置**为整页。 - 任何挂起的 **DECOM**(原点模式)状态保留,但边距重新锚定。 为何要资源门控?在 X11 / VT100 时代,应用会程序化地发 `?3h` 获得宽屏空间,意外清空用户缓冲。现代模拟器(xterm `allowC132`、putty `disable_remote_resize` 等)默认抑制 DECCOLM,除非显式启用。结果:今天的程序发送 `?3h` 在 alacritty / kitty / wezterm / ghostty / Windows Terminal 上得到的多是静默 no-op —— 安全假设是 DECCOLM 啥都不做,除非你已在目标环境验证。仅在掌控终端配置时使用 DECCOLM(或其参数化兄弟 DECSCPP);否则通过平台窗口管理协议(如 ioctl `TIOCSWINSZ`)发送 `resize` 请求。DECCOLM **持续生效**直至重置、DECSTR(软复位回到默认)或 RIS(硬复位)。

规范出处: DEC VT100 (DECCOLM) / xterm-ctlseqs

参数

示例

bash
# Probe and request 132-col, fall back gracefully:\nprintf '\033[?3h'   # request wide\nprintf '\033[6n'    # cursor position report\nIFS='[;R' read -t 0.05 -rsd R _ rows cols < /dev/tty || true\nif [ "$cols" -lt 100 ]; then echo "emulator ignored DECCOLM"; fi
python
import sys, os\nsys.stdout.write('\x1b[?3h')   # ask for 132\nsys.stdout.flush()\nrows, cols = os.get_terminal_size()\nif cols < 100:\n    print('DECCOLM not honoured — staying narrow')
go
fmt.Print("\x1b[?3h")\ndefer fmt.Print("\x1b[?3l")   // always restore — clears screen on transition
javascript
process.stdout.write('\x1b[?3l')   // explicit 80-col (default; harmless on emulators that ignore DECCOLM)
c
printf("\x1b[?3h");   /* request 132 cols */\n/* WARNING: screen now cleared. Re-render entire UI. */

终端支持

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

相关序列