Terminfo

What is Terminfo

Terminal capability database
# terminfo maps $TERM to capabilities the terminal supports
echo $TERM                               # e.g., xterm-256color, tmux-256color

# Query capabilities
infocmp                                   # dump current terminal's capabilities
infocmp xterm-256color                   # dump specific terminal type
infocmp -1 | head -20                    # one capability per line

# Key capabilities
tput colors                              # number of colors supported
tput cols                                # terminal width
tput lines                               # terminal height
tput bold                                # output bold escape sequence
tput sgr0                                # reset attributes

Common Capabilities

tput commands (portable escape sequences)
# Text formatting (portable -- works on any terminal)
tput bold                                # start bold
tput dim                                 # start dim
tput smul                                # start underline
tput rmul                                # end underline
tput rev                                 # reverse video
tput sgr0                                # reset all

# Colors
tput setaf 1                             # foreground red (0-7 basic, 0-255 extended)
tput setab 4                             # background blue
tput op                                  # reset colors

# Cursor
tput cup 5 10                            # move to row 5, col 10
tput home                                # move to 0,0
tput sc                                  # save cursor
tput rc                                  # restore cursor
tput civis                               # hide cursor
tput cnorm                               # show cursor

# Screen
tput clear                               # clear screen
tput el                                  # clear to end of line
tput ed                                  # clear to end of screen
tput smcup                               # enter alt screen
tput rmcup                               # exit alt screen

Terminfo Database

Database locations and management
# System database
ls /usr/share/terminfo/                  # compiled entries (hashed dirs)
ls /usr/share/terminfo/x/               # xterm variants

# User database
ls ~/.terminfo/ 2>/dev/null              # user overrides

# Compile a terminfo source
tic my-terminal.ti                       # compile to ~/.terminfo/
sudo tic -o /usr/share/terminfo my-terminal.ti  # system-wide

# Decompile
infocmp -x tmux-256color > tmux-256color.ti     # export source

# Compare terminals
infocmp -d xterm-256color tmux-256color         # show differences

Fixing Terminal Issues

Common $TERM problems
# Problem: colors wrong, keys not working
# Fix: set correct $TERM
export TERM=xterm-256color

# Problem: tmux colors broken
# Fix: in ~/.tmux.conf
# set -g default-terminal "tmux-256color"
# set -ag terminal-overrides ",xterm-256color:RGB"

# Problem: SSH to old server, $TERM unknown
# Fix: fallback
ssh -t server 'TERM=xterm-256color exec bash'
# Or install terminfo on remote
infocmp -x | ssh server 'tic -x /dev/stdin'

# Problem: Neovim true color not working
# Fix: check in nvim
# :checkhealth                           # look at terminal section
# :echo &termguicolors
# :set termguicolors                     # enable

# Check if terminal supports true color
printf "\e[38;2;255;100;0mTrue color test\e[0m\n"

TERM Values

$TERM When to use

xterm-256color

Most modern terminals (alacritty, default)

tmux-256color

Inside tmux sessions

screen-256color

Inside GNU screen

foot

Foot terminal (Wayland)

xterm-kitty

Kitty terminal

linux

Linux console (tty1-6, no GUI)

dumb

No capabilities (pipes, cron, CI)