From 33052018a27ff5ea498cfa21d34e15d002ab92f7 Mon Sep 17 00:00:00 2001 From: Miguel Solorio Date: Mon, 2 Jun 2025 11:20:58 -0700 Subject: Color enhancements (#680) --- packages/cli/src/ui/utils/CodeColorizer.tsx | 45 ++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'packages/cli/src/ui/utils') diff --git a/packages/cli/src/ui/utils/CodeColorizer.tsx b/packages/cli/src/ui/utils/CodeColorizer.tsx index 1916ff50..8f905498 100644 --- a/packages/cli/src/ui/utils/CodeColorizer.tsx +++ b/packages/cli/src/ui/utils/CodeColorizer.tsx @@ -94,16 +94,31 @@ export function colorizeCode( const activeTheme = themeManager.getActiveTheme(); try { - const hastTree = - !language || !lowlight.registered(language) - ? lowlight.highlightAuto(codeToHighlight) - : lowlight.highlight(language, codeToHighlight); - // Render the HAST tree using the adapted theme // Apply the theme's default foreground color to the top-level Text element + const lines = codeToHighlight.split('\n'); + const getHighlightedLines = (line: string) => + !language || !lowlight.registered(language) + ? lowlight.highlightAuto(line) + : lowlight.highlight(language, line); + return ( - - {renderHastNode(hastTree, activeTheme, undefined)} + + {lines.map((line, index) => ( + + + {`${String(index + 1).padStart(3, ' ')} `} + + + {renderHastNode( + getHighlightedLines(line), + activeTheme, + undefined, + )} + + {index < lines.length - 1 && '\n'} + + ))} ); } catch (error) { @@ -112,6 +127,20 @@ export function colorizeCode( error, ); // Fallback to plain text with default color on error - return {codeToHighlight}; + // Also display line numbers in fallback + const lines = codeToHighlight.split('\n'); + return ( + + {lines.map((line, index) => ( + + + {`${String(index + 1).padStart(3, ' ')} `} + + {line} + {index < lines.length - 1 && '\n'} + + ))} + + ); } } -- cgit v1.2.3