Many developers encounter this situation: You've compiled GNU Screen with 256-color support, your terminal emulator (like Konsole) supports 256 colors, but when you launch screen, it stubbornly sets TERM to "screen" instead of "screen-256color". This behavior persists even when you've explicitly set term screen-256color
in your .screenrc file.
GNU Screen defaults to the basic "screen" terminal type for backward compatibility. Even when compiled with 256-color support, it won't automatically upgrade the TERM variable unless explicitly configured. This conservative approach ensures screen works in all environments, though it's frustrating for modern terminal users.
Here are three reliable ways to ensure proper 256-color support:
1. .screenrc Configuration
Add these lines to your ~/.screenrc:
# Enable 256 colors
term screen-256color
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
defbce "on"
2. Shell Environment
In your shell configuration (.bashrc, .zshrc, etc.):
# Check if we're inside screen
if [ -n "$STY" ]; then
export TERM=screen-256color
fi
3. Forcing TERM at Launch
You can launch screen with the correct TERM directly:
screen -T screen-256color
To confirm 256-color support is working:
# Test 256 colors
for i in {0..255}; do
printf "\x1b[38;5;${i}mcolor${i}\x1b[0m\n"
done
You should see a smooth gradient of colors rather than just 8 or 16 basic colors.
If you're still having problems:
- Verify screen was compiled with 256-color support:
screen -v
- Check your terminal emulator supports 256 colors
- Ensure no other process is resetting TERM after screen launches
- Try a minimal .screenrc with just the term setting
When working with GNU Screen in a 256-color terminal environment, many developers face the frustrating situation where Screen insists on setting TERM="screen" despite explicit configuration for screen-256color. This happens even when:
- Your terminal emulator (like Konsole) supports 256 colors
- Screen was compiled with 256-color support
- You've added
term screen-256color
to your .screenrc
The behavior stems from how Screen handles terminal capability negotiation. When Screen starts, it performs its own terminal capability assessment and may override your settings if it detects potential compatibility issues. The algorithm prioritizes:
- Terminal capability database (/etc/terminfo or ~/.terminfo)
- Compile-time defaults
- Environment variables
Here are three proven ways to enforce 256-color support:
Method 1: Shell Wrapper
#!/bin/bash
TERM=screen-256color
export TERM
exec /usr/bin/screen "$@"
Method 2: Screenrc with Forced TERM
# ~/.screenrc
term screen-256color
# Force TERM in subshells
shell -$SHELL -c 'export TERM=screen-256color; exec $SHELL'
Method 3: System-wide terminfo
# Install proper terminfo entries
sudo apt install ncurses-term
# Or compile manually
tic /usr/share/doc/screen/examples/screen-256color.terminfo
To confirm your configuration worked:
# Inside screen session
echo $TERM
# Should output: screen-256color
# Test colors
tput colors
# Should return 256
If you still see issues, check:
- Terminfo database location with
find /usr /lib -name "*screen*"
- Screen build configuration with
screen -v
- Terminal emulator's color capabilities