mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Update diff colors (#4747)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -88,6 +88,34 @@ function renderHastNode(
|
||||
return null;
|
||||
}
|
||||
|
||||
function highlightAndRenderLine(
|
||||
line: string,
|
||||
language: string | null,
|
||||
theme: Theme,
|
||||
): React.ReactNode {
|
||||
try {
|
||||
const getHighlightedLine = () =>
|
||||
!language || !lowlight.registered(language)
|
||||
? lowlight.highlightAuto(line)
|
||||
: lowlight.highlight(language, line);
|
||||
|
||||
const renderedNode = renderHastNode(getHighlightedLine(), theme, undefined);
|
||||
|
||||
return renderedNode !== null ? renderedNode : line;
|
||||
} catch (_error) {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
export function colorizeLine(
|
||||
line: string,
|
||||
language: string | null,
|
||||
theme?: Theme,
|
||||
): React.ReactNode {
|
||||
const activeTheme = theme || themeManager.getActiveTheme();
|
||||
return highlightAndRenderLine(line, language, activeTheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders syntax-highlighted code for Ink applications using a selected theme.
|
||||
*
|
||||
@@ -123,11 +151,6 @@ export function colorizeCode(
|
||||
}
|
||||
}
|
||||
|
||||
const getHighlightedLines = (line: string) =>
|
||||
!language || !lowlight.registered(language)
|
||||
? lowlight.highlightAuto(line)
|
||||
: lowlight.highlight(language, line);
|
||||
|
||||
return (
|
||||
<MaxSizedBox
|
||||
maxHeight={availableHeight}
|
||||
@@ -136,17 +159,19 @@ export function colorizeCode(
|
||||
overflowDirection="top"
|
||||
>
|
||||
{lines.map((line, index) => {
|
||||
const renderedNode = renderHastNode(
|
||||
getHighlightedLines(line),
|
||||
const contentToRender = highlightAndRenderLine(
|
||||
line,
|
||||
language,
|
||||
activeTheme,
|
||||
undefined,
|
||||
);
|
||||
|
||||
const contentToRender = renderedNode !== null ? renderedNode : line;
|
||||
return (
|
||||
<Box key={index}>
|
||||
<Text color={activeTheme.colors.Gray}>
|
||||
{`${String(index + 1 + hiddenLinesCount).padStart(padWidth, ' ')} `}
|
||||
{`${String(index + 1 + hiddenLinesCount).padStart(
|
||||
padWidth,
|
||||
' ',
|
||||
)} `}
|
||||
</Text>
|
||||
<Text color={activeTheme.defaultColor} wrap="wrap">
|
||||
{contentToRender}
|
||||
|
||||
Reference in New Issue
Block a user