-
-
Notifications
You must be signed in to change notification settings - Fork 35.1k
Description
Bug
In lib/internal/tty.js, getColorDepth() checks env.TMUX (line 174) before env.COLORTERM (line 215). When TMUX is set, it returns COLORS_256 (8) immediately, never reaching the COLORTERM === 'truecolor' check that would return COLORS_16m (24).
tmux has supported true color since v2.2 (2016). Modern tmux sets COLORTERM=truecolor when the outer terminal supports RGB via terminal-features or terminal-overrides. The current ordering ignores this.
Note: PR #30474 previously reordered COLORTERM before the TERM check but did not address the TMUX check ordering.
Reproduction
const tty = require('tty');
console.log('TMUX:', process.env.TMUX || '(unset)');
console.log('COLORTERM:', process.env.COLORTERM || '(unset)');
console.log('getColorDepth():', process.stdout.getColorDepth());Inside tmux (with COLORTERM=truecolor):
TMUX: /private/tmp/tmux-501/default,9842,1
COLORTERM: truecolor
getColorDepth(): 8 # ← wrong, should be 24
With TMUX= unset:
TMUX: (unset)
COLORTERM: truecolor
getColorDepth(): 24 # ← correct
Suggested fix
Move the COLORTERM truecolor/24bit check (line 215) before the TMUX check (line 174):
// Check COLORTERM first — tmux sets this when RGB is supported
if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit') {
return COLORS_16m;
}
if (env.TMUX) {
return COLORS_256;
}This preserves the TMUX → 256 fallback for tmux sessions that don't have truecolor configured, while correctly returning 16m for those that do.
Related
- PR tty: truecolor check moved before 256 check #30474 — moved truecolor check before
TERM256 check (but not beforeTMUX) - Bun has the same bug (filed at
getColorDepth()returns 8 (256-color) inside tmux despite COLORTERM=truecolor oven-sh/bun#28463), inherited from this code