Skip to content

Commit 5ae61a9

Browse files
committed
fix(tui): avoid gradient interpolation for non-hex colors
1 parent e366de7 commit 5ae61a9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/tui/components/shared/GradientText.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export interface GradientTextProps {
2929
/**
3030
* Generate an array of interpolated colors for gradient text
3131
*/
32+
function isHexColor(color: string): boolean {
33+
return /^#([a-f\d]{6})$/i.test(color);
34+
}
35+
3236
function generateGradientColors(
3337
startColor: string,
3438
endColor: string,
@@ -37,6 +41,12 @@ function generateGradientColors(
3741
if (steps <= 0) return [];
3842
if (steps === 1) return [startColor];
3943

44+
// If we don't have hex colors (e.g. ANSI/basic palette names like "magenta"),
45+
// we can't interpolate safely. Fall back to a flat color.
46+
if (!isHexColor(startColor) || !isHexColor(endColor)) {
47+
return Array.from({ length: steps }, () => startColor);
48+
}
49+
4050
const colors: string[] = [];
4151
for (let i = 0; i < steps; i++) {
4252
const factor = i / (steps - 1);

0 commit comments

Comments
 (0)