Skip to main content
ansicode

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 capterminfo nameSequenceNotes
sgr0exit_attribute_mode\x1b[0mReset every text attribute and colour. Equivalent to SGR 0. Pair this with any attribute you turn on.SGR 0 — Reset / Normal
boldenter_bold_mode\x1b[1mBold / increased intensity. Turn off with sgr0 or SGR 22.SGR 1 — Bold / Increased intensity
dimenter_dim_mode\x1b[2mHalf-bright (faint). SGR 2.SGR 2 — Dim / Faint
sitmenter_italics_mode\x1b[3mItalic. Modern terminals support it; the Linux console and cmd.exe do not.SGR 3 — Italic
ritmexit_italics_mode\x1b[23mTurn italic off without clearing other attributes.SGR 3 — Italic
smulenter_underline_mode\x1b[4mUnderline on. SGR 4.SGR 4 — Underline
rmulexit_underline_mode\x1b[24mUnderline off (SGR 24) — only this attribute, others preserved.SGR 4 — Underline
blinkenter_blink_mode\x1b[5mSlow blink. Off by default in iTerm2 / kitty; usually annoying — prefer colour change.SGR 5 — Blink (slow)
reventer_reverse_mode\x1b[7mReverse video — swap foreground / background. SGR 7.SGR 7 — Reverse video
smsoenter_standout_mode\x1b[7mStandout — historically distinct from reverse, but modern terminals map it to SGR 7 (reverse).SGR 7 — Reverse video
rmsoexit_standout_mode\x1b[27mExit standout / reverse via SGR 27 — clears just this attribute.SGR 7 — Reverse video
invisenter_secure_mode\x1b[8mHidden text (SGR 8). Useful for masked passwords; still copy-pasteable.SGR 8 — Conceal / Hidden

Colour

tput capterminfo nameSequenceNotes
setafset_a_foregroundvariesSet 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)
setabset_a_backgroundvariesSet background colour by index — mirror of setaf.SGR 40–47 — Background color (8 basic)
oporig_pair\x1b[39;49mReset foreground AND background to terminal defaults without touching other SGR state.SGR 39 — Default foreground color

Cursor

tput capterminfo nameSequenceNotes
cupcursor_addressvariesMove 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
homecursor_home\x1b[HMove cursor to (1, 1).CUP — Set cursor position
cuu1cursor_up\x1b[AUp one line (CUU 1).CUU / CUD / CUF / CUB — Move cursor
cud1cursor_down\nDown 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
cuf1cursor_right\x1b[CRight one column (CUF 1).CUU / CUD / CUF / CUB — Move cursor
cub1cursor_left\bLeft one column — terminfo maps this to bare BS (\b, 0x08). Use cub for N: \x1b[ND.CUU / CUD / CUF / CUB — Move cursor
hpacolumn_addressvariesMove to a specific column on the current row — \x1b[<col+1>G (CHA).CHA — Cursor horizontal absolute (column)
civiscursor_invisible\x1b[?25lHide the text cursor. Always pair with cnorm on exit.DECTCEM ?25 — Show/hide cursor
cnormcursor_normal\x1b[?25hRestore the text cursor (DECTCEM ?25h).DECTCEM ?25 — Show/hide cursor
scsave_cursor\x1b7Save cursor position (DECSC). Paired with rc.DECSC / DECRC — Save and restore cursor
rcrestore_cursor\x1b8Restore cursor position previously saved with sc (DECRC).DECSC / DECRC — Save and restore cursor

Erase

tput capterminfo nameSequenceNotes
clearclear_screen\x1b[H\x1b[2JHome cursor then erase entire display (ED 2). The shell command clear ultimately emits this.ED — Erase in display (\x1b[2J clear screen)
edclr_eos\x1b[JErase from cursor to end of display (ED 0, default).ED — Erase in display (\x1b[2J clear screen)
elclr_eol\x1b[KErase from cursor to end of line (EL 0). The progress-bar idiom is \r + el.EL — Erase in line (\x1b[K)
el1clr_bol\x1b[1KErase from beginning of line to cursor (EL 1).EL — Erase in line (\x1b[K)

Screen / mode

tput capterminfo nameSequenceNotes
smcupenter_ca_mode\x1b[?1049hEnter the alternate screen buffer. vim, less, htop, top start with this.DECSET 1049 — Alternate screen buffer
rmcupexit_ca_mode\x1b[?1049lLeave the alternate screen buffer — restores original buffer + cursor.DECSET 1049 — Alternate screen buffer
resetreset_1string (rs1)\x1bcHard terminal reset — emit RIS (\x1bc). What tput reset and reset(1) ultimately send.RIS — Reset to Initial State (full terminal reset)

Input (keyboard)

tput capterminfo nameSequenceNotes
kcuu1key_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
kcud1key_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
kcub1key_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
kcuf1key_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
khomekey_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
kendkey_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
kppkey_ppage\x1b[5~Page Up. The 5~ CSI tilde encoding is portable across xterm / rxvt / linux console. Modifiers: Shift+PgUp = \x1b[5;2~.
knpkey_npage\x1b[6~Page Down. Mirrors kpp with selector 6. Linux console may legacy-emit \x1b[G in some modes — check infocmp linux.
kbskey_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.
kdch1key_dc\x1b[3~Delete (forward, not Backspace). 3~ selector. Shift+Delete = \x1b[3;2~. Don't confuse with kbs.
kich1key_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.
kf1key_f1\x1bOPF1. 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.
kf5key_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~.
kf12key_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.
smkxkeypad_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 >)
rmkxkeypad_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"