(env: CliEnv = getCliEnv())
| 22 | let _truecolorSupport: boolean | null = null |
| 23 | |
| 24 | export function supportsTruecolor(env: CliEnv = getCliEnv()): boolean { |
| 25 | if (_truecolorSupport !== null) { |
| 26 | return _truecolorSupport |
| 27 | } |
| 28 | |
| 29 | const termProgram = env.TERM_PROGRAM?.toLowerCase() ?? '' |
| 30 | |
| 31 | // Terminal.app (Apple_Terminal) does NOT support truecolor - only 256 colors |
| 32 | if (termProgram === 'apple_terminal') { |
| 33 | _truecolorSupport = false |
| 34 | return false |
| 35 | } |
| 36 | |
| 37 | const colorterm = env.COLORTERM?.toLowerCase() |
| 38 | if (colorterm === 'truecolor' || colorterm === '24bit') { |
| 39 | _truecolorSupport = true |
| 40 | return true |
| 41 | } |
| 42 | |
| 43 | // Some terminals that are known to support truecolor |
| 44 | const truecolorTerminals = [ |
| 45 | 'iterm.app', |
| 46 | 'hyper', |
| 47 | 'wezterm', |
| 48 | 'alacritty', |
| 49 | 'kitty', |
| 50 | 'ghostty', |
| 51 | 'vscode', |
| 52 | ] |
| 53 | |
| 54 | if (truecolorTerminals.some(t => termProgram.includes(t))) { |
| 55 | _truecolorSupport = true |
| 56 | return true |
| 57 | } |
| 58 | |
| 59 | // Check TERM for known truecolor-capable values |
| 60 | const term = env.TERM?.toLowerCase() ?? '' |
| 61 | if (term.includes('truecolor') || term.includes('24bit')) { |
| 62 | _truecolorSupport = true |
| 63 | return true |
| 64 | } |
| 65 | |
| 66 | // xterm-kitty, alacritty, etc. |
| 67 | if (term === 'xterm-kitty' || term === 'alacritty' || term.includes('ghostty')) { |
| 68 | _truecolorSupport = true |
| 69 | return true |
| 70 | } |
| 71 | |
| 72 | _truecolorSupport = false |
| 73 | return false |
| 74 | } |
| 75 | |
| 76 | |
| 77 |
no test coverage detected