Skip to main content
ansicode

CSI Ps i — Media Copy (MC) — printer-on / printer-off / print line

ECMA-48 §8.3.82 control that historically routed terminal output to an attached printer. Survives today as the 'print screen' hook on xterm/mlterm, the IBM-3270 emulator pass-through, and as private-mode CSI ? 4 / 5 i auto-print toggles consumed by expect-style automation.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b[0i / \x1b[4i / \x1b[5i / \x1b[?4i / \x1b[?5i
\\033[\033[5i (printer-on) \033[4i (printer-off)
\\e[\e[5i / \e[4i
ESC [ESC [ Ps i (Ps ∈ {0,1,4,5}) / ESC [ ? Ps i
hex1b 5b 35 69 (printer-on) / 1b 5b 34 69 (printer-off)

Description

Media Copy (MC) is the ECMA-48 mechanism for diverting terminal output to a secondary stream — historically an attached line printer or a serial-port-attached page printer. The standard parameters: - \x1b[0i (or just \x1b[i) — print page. Send the current screen contents to the printer as a one-shot. The terminal handles framing (form-feed, page-end). xterm honours this by writing to the program named in the printerCommand X resource (typically lpr). - \x1b[1iprint line. One-line variant of 0i. - \x1b[4iprinter-off (Media Copy 'deselect'). Stop the stream-divert started by 5i. After this, output goes only to the screen. - \x1b[5iprinter-on (Media Copy 'select'). Start diverting all subsequent terminal output to the printer until a matching 4i. Often called *transparent print mode*. The screen receives nothing in this state.

Private-prefix DEC variants (\x1b[?Ps i): - \x1b[?1i — print cursor line (single line, no form-feed). - \x1b[?4i — turn auto-print off. - \x1b[?5i — turn auto-print on. Whenever the cursor advances past the right margin or a \n flushes a line, that line is also sent to the printer. - \x1b[?10i / \x1b[?11i — print the composed display (VT300+); print every character including received controls.

Why it still matters in 2026 - IBM 3270 / 5250 emulator stacks (x3270, wc3270, tn5270) flow MC through the host application to a real or virtual LPT device. Older mainframe batch jobs still expect the \x1b[5i…\x1b[4i envelope to bracket print data. - xterm + mlterm honour 0i and 5i/4i if printerCommand is set in the X resources — the modern equivalent is printerCommand: cat > /tmp/xterm.dump. Useful for screen capture / debugging without tmux capture-pane. - expect scripts against legacy systems use \x1b[5i\x1b[4i as a 'capture this block' marker because almost no modern emulator implements the divert, so the bytes are emitted to the screen and visible to expect's pattern matcher.

Coverage is mostly no-op today: xterm + mlterm = full (gated on printerCommand resource). Konsole = partial (parses, no-op without explicit printer support). Linux console = partial (5i / 4i work if lp daemon attached). WezTerm + Kitty + Alacritty + iTerm2 + gnome-terminal + Ghostty + Windows Terminal + cmd / ConPTY + macOS Terminal = silent no-op (the bytes pass through the parser without effect). Do not rely on the divert outside the xterm + mlterm + 3270 path.

Spec citation: ECMA-48 §8.3.82 (MC) / xterm-ctlseqs (CSI Ps i, CSI ? Ps i)

Parameters

Ps = 0Print page — send current screen to printer (one-shot, with form-feed).
Ps = 1Print line — single-line variant.
Ps = 4Printer-off (deselect Media Copy stream).
Ps = 5Printer-on (select Media Copy stream — transparent print mode).
? Ps = 1Print cursor line (DEC, single-line, no form-feed).
? Ps = 4 / 5Auto-print off / on — each cursor line-wrap also goes to printer.

Examples

bash
# xterm with printerCommand='cat > /tmp/screen.dump' — capture current screen.\nprintf '\\033[0i'\n# Bracketed print: every byte between 5i and 4i goes to the printer.\nprintf '\\033[5i'; cat report.txt; printf '\\033[4i'
python
import sys\n# expect-style capture marker — emits visible bytes on non-xterm.\nsys.stdout.write('\\x1b[5i')\nsys.stdout.flush()\n# (expect script greps for the literal bytes; xterm diverts them silently)
go
// Auto-print every line as it scrolls (DEC private).\nfmt.Print(\"\\x1b[?5i\")     // auto-print on\ndefer fmt.Print(\"\\x1b[?4i\")  // auto-print off on exit
javascript
// 3270 emulator print envelope around report data.\nprocess.stdout.write('\\x1b[5i' + reportData + '\\x1b[4i');
c
/* Print cursor line, no form-feed. */\nprintf(\"\\x1b[?1i\");\nfflush(stdout);

Terminal support

xterm
yes
Linux console (fbcon)
partial
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
partial
tmux
yes
GNU screen
yes

Related sequences