From 161ba28966a09d00d11ae92340154f1b07851b4f Mon Sep 17 00:00:00 2001 From: Clay Date: Tue, 14 Apr 2026 15:08:51 -0400 Subject: [PATCH] fix(core): detect kmscon terminal as supporting true color (#25282) Co-authored-by: Adib234 <30782825+Adib234@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/core/src/utils/compatibility.test.ts | 26 +++++++++++++++++++ packages/core/src/utils/compatibility.ts | 8 +++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/core/src/utils/compatibility.test.ts b/packages/core/src/utils/compatibility.test.ts index 28fa26453c..f3ac7e35e5 100644 --- a/packages/core/src/utils/compatibility.test.ts +++ b/packages/core/src/utils/compatibility.test.ts @@ -195,6 +195,7 @@ describe('compatibility', () => { desc: '256 colors are not supported', }, ])('should return $expected when $desc', ({ depth, term, expected }) => { + vi.stubEnv('COLORTERM', ''); process.stdout.getColorDepth = vi.fn().mockReturnValue(depth); if (term !== undefined) { vi.stubEnv('TERM', term); @@ -203,6 +204,13 @@ describe('compatibility', () => { } expect(supports256Colors()).toBe(expected); }); + + it('should return true when COLORTERM is kmscon', () => { + process.stdout.getColorDepth = vi.fn().mockReturnValue(4); + vi.stubEnv('TERM', 'linux'); + vi.stubEnv('COLORTERM', 'kmscon'); + expect(supports256Colors()).toBe(true); + }); }); describe('supportsTrueColor', () => { @@ -230,6 +238,12 @@ describe('compatibility', () => { expected: true, desc: 'getColorDepth returns >= 24', }, + { + colorterm: 'kmscon', + depth: 4, + expected: true, + desc: 'COLORTERM is kmscon', + }, { colorterm: '', depth: 8, @@ -409,6 +423,18 @@ describe('compatibility', () => { ); }); + it('should return no color warnings for kmscon terminal', () => { + vi.mocked(os.platform).mockReturnValue('linux'); + vi.stubEnv('TERMINAL_EMULATOR', ''); + vi.stubEnv('TERM', 'linux'); + vi.stubEnv('COLORTERM', 'kmscon'); + process.stdout.getColorDepth = vi.fn().mockReturnValue(4); + + const warnings = getCompatibilityWarnings(); + expect(warnings.find((w) => w.id === '256-color')).toBeUndefined(); + expect(warnings.find((w) => w.id === 'true-color')).toBeUndefined(); + }); + it('should return no warnings in a standard environment with true color', () => { vi.mocked(os.platform).mockReturnValue('darwin'); vi.stubEnv('TERMINAL_EMULATOR', ''); diff --git a/packages/core/src/utils/compatibility.ts b/packages/core/src/utils/compatibility.ts index 8a997b42cf..47ef078831 100644 --- a/packages/core/src/utils/compatibility.ts +++ b/packages/core/src/utils/compatibility.ts @@ -85,6 +85,11 @@ export function supports256Colors(): boolean { return true; } + // Terminals supporting true color (like kmscon) also support 256 colors + if (supportsTrueColor()) { + return true; + } + return false; } @@ -95,7 +100,8 @@ export function supportsTrueColor(): boolean { // Check COLORTERM environment variable if ( process.env['COLORTERM'] === 'truecolor' || - process.env['COLORTERM'] === '24bit' + process.env['COLORTERM'] === '24bit' || + process.env['COLORTERM'] === 'kmscon' ) { return true; }