terminfo cap → ANSI sequence mapping
ncurses / terminfo capabilities (the names you pass to tput) and the ANSI / VT escape sequences they expand to on a modern xterm-256color terminal. Use this when porting legacy shell scripts off tput to direct escapes, debugging a TUI that emits the "wrong" bytes, or just learning what tput setaf 1 actually sends.
Attributes (SGR)
| tput cap | terminfo name | Sequence | Notes |
|---|---|---|---|
| sgr0 | exit_attribute_mode | \x1b[0m | Reset every text attribute and colour. Equivalent to SGR 0. Pair this with any attribute you turn on. — SGR 0 — Reset / Normal |
| bold | enter_bold_mode | \x1b[1m | Bold / increased intensity. Turn off with sgr0 or SGR 22. — SGR 1 — Bold / Increased intensity |
| dim | enter_dim_mode | \x1b[2m | Half-bright (faint). SGR 2. — SGR 2 — Dim / Faint |
| sitm | enter_italics_mode | \x1b[3m | Italic. Modern terminals support it; the Linux console and cmd.exe do not. — SGR 3 — Italic |
| ritm | exit_italics_mode | \x1b[23m | Turn italic off without clearing other attributes. — SGR 3 — Italic |
| smul | enter_underline_mode | \x1b[4m | Underline on. SGR 4. — SGR 4 — Underline |
| rmul | exit_underline_mode | \x1b[24m | Underline off (SGR 24) — only this attribute, others preserved. — SGR 4 — Underline |
| blink | enter_blink_mode | \x1b[5m | Slow blink. Off by default in iTerm2 / kitty; usually annoying — prefer colour change. — SGR 5 — Blink (slow) |
| rev | enter_reverse_mode | \x1b[7m | Reverse video — swap foreground / background. SGR 7. — SGR 7 — Reverse video |
| smso | enter_standout_mode | \x1b[7m | Standout — historically distinct from reverse, but modern terminals map it to SGR 7 (reverse). — SGR 7 — Reverse video |
| rmso | exit_standout_mode | \x1b[27m | Exit standout / reverse via SGR 27 — clears just this attribute. — SGR 7 — Reverse video |
| invis | enter_secure_mode | \x1b[8m | Hidden text (SGR 8). Useful for masked passwords; still copy-pasteable. — SGR 8 — Conceal / Hidden |
Colour
| tput cap | terminfo name | Sequence | Notes |
|---|---|---|---|
| setaf | set_a_foreground | varies | Set foreground colour by index. tput setaf 1 → \x1b[31m (red); tput setaf 9 → \x1b[91m (bright red); 256-colour and TrueColor capable terminals accept higher indices. — SGR 30–37 — Foreground color (8 basic) |
| setab | set_a_background | varies | Set background colour by index — mirror of setaf. — SGR 40–47 — Background color (8 basic) |
| op | orig_pair | \x1b[39;49m | Reset foreground AND background to terminal defaults without touching other SGR state. — SGR 39 — Default foreground color |
Cursor
| tput cap | terminfo name | Sequence | Notes |
|---|---|---|---|
| cup | cursor_address | varies | Move cursor to (row, col), 0-indexed at terminfo level but emitted as 1-indexed \x1b[<r+1>;<c+1>H (CUP). — CUP — Set cursor position |
| home | cursor_home | \x1b[H | Move cursor to (1, 1). — CUP — Set cursor position |
| cuu1 | cursor_up | \x1b[A | Up one line (CUU 1). — CUU / CUD / CUF / CUB — Move cursor |
| cud1 | cursor_down | \n | Down one line — on most modern terminfo this is the bare \n (LF). Use cud (parameterised) for N rows: \x1b[NB. — CUU / CUD / CUF / CUB — Move cursor |
| cuf1 | cursor_right | \x1b[C | Right one column (CUF 1). — CUU / CUD / CUF / CUB — Move cursor |
| cub1 | cursor_left | \b | Left one column — terminfo maps this to bare BS (\b, 0x08). Use cub for N: \x1b[ND. — CUU / CUD / CUF / CUB — Move cursor |
| hpa | column_address | varies | Move to a specific column on the current row — \x1b[<col+1>G (CHA). — CHA — Cursor horizontal absolute (column) |
| civis | cursor_invisible | \x1b[?25l | Hide the text cursor. Always pair with cnorm on exit. — DECTCEM ?25 — Show/hide cursor |
| cnorm | cursor_normal | \x1b[?25h | Restore the text cursor (DECTCEM ?25h). — DECTCEM ?25 — Show/hide cursor |
| sc | save_cursor | \x1b7 | Save cursor position (DECSC). Paired with rc. — DECSC / DECRC — Save and restore cursor |
| rc | restore_cursor | \x1b8 | Restore cursor position previously saved with sc (DECRC). — DECSC / DECRC — Save and restore cursor |
Erase
| tput cap | terminfo name | Sequence | Notes |
|---|---|---|---|
| clear | clear_screen | \x1b[H\x1b[2J | Home cursor then erase entire display (ED 2). The shell command clear ultimately emits this. — ED — Erase in display (\x1b[2J clear screen) |
| ed | clr_eos | \x1b[J | Erase from cursor to end of display (ED 0, default). — ED — Erase in display (\x1b[2J clear screen) |
| el | clr_eol | \x1b[K | Erase from cursor to end of line (EL 0). The progress-bar idiom is \r + el. — EL — Erase in line (\x1b[K) |
| el1 | clr_bol | \x1b[1K | Erase from beginning of line to cursor (EL 1). — EL — Erase in line (\x1b[K) |
Screen / mode
| tput cap | terminfo name | Sequence | Notes |
|---|---|---|---|
| smcup | enter_ca_mode | \x1b[?1049h | Enter the alternate screen buffer. vim, less, htop, top start with this. — DECSET 1049 — Alternate screen buffer |
| rmcup | exit_ca_mode | \x1b[?1049l | Leave the alternate screen buffer — restores original buffer + cursor. — DECSET 1049 — Alternate screen buffer |
| reset | reset_1string (rs1) | \x1bc | Hard terminal reset — emit RIS (\x1bc). What tput reset and reset(1) ultimately send. — RIS — Reset to Initial State (full terminal reset) |
Input (keyboard)
| tput cap | terminfo name | Sequence | Notes |
|---|---|---|---|
| kcuu1 | key_up | \x1b[A (\x1bOA in DECCKM application mode) | Up arrow. \x1b[A in normal cursor-key mode; \x1bOA (SS3) once an app turns DECCKM on via smkx. Apps like vim and less bind both. — CUU / CUD / CUF / CUB — Move cursor |
| kcud1 | key_down | \x1b[B (\x1bOB in app mode) | Down arrow. Same DECCKM split as kcuu1. Modifiers append ;<mod> before the letter: Shift+Down = \x1b[1;2B. — CUU / CUD / CUF / CUB — Move cursor |
| kcub1 | key_left | \x1b[D (\x1bOD in app mode) | Left arrow. Bash readline binds \e[D to backward-char by default — same byte sequence, just read at the input side. — CUU / CUD / CUF / CUB — Move cursor |
| kcuf1 | key_right | \x1b[C (\x1bOC in app mode) | Right arrow. Pair with kcub1 (left) in bindkey/inputrc to wire forward-char/backward-char. — CUU / CUD / CUF / CUB — Move cursor |
| khome | key_home | \x1bOH (or \x1b[1~ on rxvt-class) | Home key. xterm-class terminals send \x1bOH (SS3 H); rxvt-class send \x1b[1~. readline \e[H also binds it on many setups. — CUP — Set cursor position |
| kend | key_end | \x1bOF (or \x1b[4~ on rxvt-class) | End key. xterm-class \x1bOF; rxvt-class \x1b[4~. Pair with khome in input-binding tables. — CUP — Set cursor position |
| kpp | key_ppage | \x1b[5~ | Page Up. The 5~ CSI tilde encoding is portable across xterm / rxvt / linux console. Modifiers: Shift+PgUp = \x1b[5;2~. |
| knp | key_npage | \x1b[6~ | Page Down. Mirrors kpp with selector 6. Linux console may legacy-emit \x1b[G in some modes — check infocmp linux. |
| kbs | key_backspace | \x7f (or \x08 on Linux console / cmd.exe) | Backspace. The famous fork: xterm / iTerm2 / Windows Terminal send \x7f (DEL); Linux console + cmd.exe send \x08 (BS). Bind both in inputrc. |
| kdch1 | key_dc | \x1b[3~ | Delete (forward, not Backspace). 3~ selector. Shift+Delete = \x1b[3;2~. Don't confuse with kbs. |
| kich1 | key_ic | \x1b[2~ | Insert key. 2~ selector. Some emulators (macOS Terminal) don't have a physical Insert key but still emit \x1b[2~ from fn-Enter or a defined shortcut. |
| kf1 | key_f1 | \x1bOP | F1. F1–F4 use SS3 form (\x1bO + letter P/Q/R/S) — historical hold-over from DEC VT100 Help / Do keys. F5+ switches to CSI tilde. |
| kf5 | key_f5 | \x1b[15~ | F5. The CSI-tilde-with-gaps numbering kicks in: F5=15~, F6=17~ (16 skipped), F7=18~, F8=19~, F9=20~, F10=21~, F11=23~ (22 skipped), F12=24~. |
| kf12 | key_f12 | \x1b[24~ | F12. Tail end of the F-key set. Modern keyboards rarely physically have F13+ but terminfo defines kf13..kf63 — they're chord remaps (Shift+F1 = F13, etc.) in the xterm tradition. |
| smkx | keypad_xmit | \x1b[?1h\x1b= | Enter application-keypad mode — flips DECCKM (\x1b[?1h) so arrows send SS3 forms (\x1bOA..), then DECKPAM (\x1b=) so the numpad sends SS3-prefixed codes. Apps like vim / less / fzf emit this on startup. — DECKPAM / DECKPNM — Keypad application / numeric mode (ESC = / ESC >) |
| rmkx | keypad_local | \x1b[?1l\x1b> | Exit application-keypad mode — DECCKM off (\x1b[?1l) + DECKPNM (\x1b>). What apps SHOULD send on exit; vim crash / lazy SIGINT handlers that skip this leave the terminal in app-mode (arrows emit \eOA instead of \e[A, breaking readline-style input). — DECKPAM / DECKPNM — Keypad application / numeric mode (ESC = / ESC >) |
Usage
On any Unix-like system, infocmp -1 <term> dumps the full capability table for a given terminal. Inside scripts, tput <cap> resolves the cap against $TERM and prints the bytes, which is portable across xterm / Linux console / macOS Terminal / kitty / wezterm and degrades gracefully on dumb terminals.
# print the underlying escape for any cap:
infocmp -1 xterm-256color | grep -E '^\s(setaf|cup|civis|smcup)='
# emit a cap from a shell script:
RED=$(tput setaf 1)
BOLD=$(tput bold)
RESET=$(tput sgr0)
printf '%s%serror:%s permission denied\n' "$BOLD" "$RED" "$RESET"