DECDMAC / DECINVM — Define & invoke macro (DCS Pn ; Pn ; Pn ! z ... ST / CSI Pn * z)
Store a byte sequence under a numeric handle (DECDMAC), then replay it on demand (DECINVM) — DEC VT520's terminal-side macro recorder.
Byte forms
Every common string-literal form so you can paste-and-search either direction.
\x1bP<Pid>;<Pdt>;<Penc>!z<MACRO-BODY>\x1b\\ (define) \x1b[<Pid>*z (invoke)\033P<Pid>;<Pdt>;<Penc>!z<body>\033\\ / \033[<Pid>*z\eP<Pid>;<Pdt>;<Penc>!z<body>\e\\ / \e[<Pid>*zESC P Pid ; Pdt ; Penc ! z BODY ESC \ / ESC [ Pid * z1b 50 ... 21 7a ... 1b 5c / 1b 5b ... 2a 7aDescription
DEC VT520 / VT525 macro facility — two paired sequences. **DECDMAC** (Define Macro) is a DCS frame with intermediate `!` (0x21) and final `z` (0x7a) that stores the body `<MACRO-BODY>` under integer handle `Pid` (0–63). Parameters: - `Pid` — macro number (0–63). - `Pdt` (delete-type) — `0` (default) overwrite this macro only; `1` delete **all** macros before storing. - `Penc` (encoding) — `0` (default) body is plain 7-bit / 8-bit terminal bytes; `1` body is hex-encoded (every two hex digits = one byte) — the hex form lets the macro safely contain ESC, ST, `;`, and other parser-sensitive bytes that would otherwise terminate the DCS frame early. **DECINVM** (Invoke Macro) is a CSI sequence with intermediate `*` (0x2a) and final `z` — `\x1b[<Pid>*z` replays whatever was stored under that handle as if those bytes had arrived freshly on the wire (any embedded SGR, cursor moves, OSC, etc. all execute in normal parser state). **Use case** (historical): forms-data-entry terminals — a host application defined a stable set of cursor-position + box-drawing macros at session start, then drove the screen via short DECINVM calls instead of repeating the heavy CSI sequences thousands of times across the page. Saves wire bytes on slow serial links (the original motivation), and lets the terminal cache the cursor-positioning work. **Modern relevance**: essentially nil. Only xterm implements both at meaningful fidelity (with `disallowedColors` / `allowMacro` resources defaulting to **off** for security — a remote process defining macros that later get invoked is a small but real shell-integration / clipboard-injection attack surface). Modern emulators (alacritty / kitty / wezterm / ghostty / Windows Terminal) silently ignore both. Use for: VT520-faithful emulator test suites, forms-terminal preservation work, and exotic demos.
Spec citation: DEC VT520 RM (DECDMAC / DECINVM) / xterm-ctlseqs
Parameters
| Pid | Macro number 0–63 (define and invoke share the same numeric namespace). |
| Pdt | Delete-type for DECDMAC: 0 = overwrite this slot only, 1 = delete ALL macros first. |
| Penc | Encoding for the DECDMAC body: 0 = raw bytes, 1 = hex-encoded (safe for ESC / ST / `;`). |
Examples
# Define macro 1 = 'cursor-home + clear screen', then invoke twice.\nprintf '\033P1;0;0!z\033[H\033[2J\033\\\\'\nprintf '\033[1*z' # invoke — clears screen\nprintf '\033[1*z' # invoke again — still clearsimport sys\n# Hex-encoded body so the macro can contain ESC safely:\nbody_hex = '1b5b481b5b324a' # ESC[H ESC[2J\nsys.stdout.write(f'\x1bP2;0;1!z{body_hex}\x1b\\\\')\nsys.stdout.write('\x1b[2*z') # invoke macro 2// Define a 'red bold' SGR macro then invoke at every log line:\nfmt.Print("\x1bP3;0;0!z\x1b[1;31m\x1b\\\\")\nfor _, line := range lines { fmt.Print("\x1b[3*z" + line + "\x1b[0m\n") }// Wipe all macros and store a fresh one in slot 0:\nprocess.stdout.write('\x1bP0;1;0!zHELLO\x1b\\\\')\nprocess.stdout.write('\x1b[0*z') // prints HELLO/* Define macro 7 = SGR reset; invoke at end of every styled span. */\nprintf("\x1bP7;0;0!z\x1b[0m\x1b\\\\");\nfor (int i = 0; i < n; ++i) {\n print_colored(items[i]);\n printf("\x1b[7*z");\n}Terminal support
- xterm
- yes
- Linux console (fbcon)
- no
- macOS Terminal.app
- no
- iTerm2
- no
- Windows Terminal
- no
- cmd.exe / ConPTY
- no
- kitty
- no
- alacritty
- no
- WezTerm
- no
- Ghostty
- no
- GNOME Terminal
- no
- Konsole
- no
- tmux
- no
- GNU screen
- no
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yes | no | no | no | no | no | no | no | no | no | no | no | no | no |