File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
src/tui/components/shared Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff 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+
3236function 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 ) ;
You can’t perform that action at this time.
0 commit comments