Refactor: Improve UI rendering and address code review comments

This commit addresses several code review comments primarily focused on improving the rendering and stability of the CLI UI.

Key changes include:
- Passing `isPending` and `availableTerminalHeight` props to `MarkdownDisplay` to enable more intelligent rendering of content, especially for pending messages and code blocks.
- Adjusting height calculations in `ToolGroupMessage` and `ToolMessage` to more accurately reflect available space.
- Refining the logic in `App.tsx` for measuring and utilizing terminal height, including renaming `footerRef` to `mainControlsRef` for clarity.
- Ensuring consistent prop drilling for `isPending` and `availableTerminalHeight` through `HistoryItemDisplay`, `GeminiMessage`, and `GeminiMessageContent`.
- In `MarkdownDisplay`, when `isPending` is true and content exceeds `availableTerminalHeight`, the code block will now be truncated with a "... generating more ..." message. If there's insufficient space even for the
message, a simpler "... code is being written ..." will be shown.
This commit is contained in:
Taylor Mullen
2025-05-15 22:56:03 -07:00
committed by N. Taylor Mullen
parent 33743d347b
commit 9c46acc793
7 changed files with 114 additions and 29 deletions

View File

@@ -17,18 +17,30 @@ import { Box } from 'ink';
interface HistoryItemDisplayProps {
item: HistoryItem;
availableTerminalHeight: number;
isPending: boolean;
}
export const HistoryItemDisplay: React.FC<HistoryItemDisplayProps> = ({
item,
availableTerminalHeight,
isPending,
}) => (
<Box flexDirection="column" key={item.id}>
{/* Render standard message types */}
{item.type === 'user' && <UserMessage text={item.text} />}
{item.type === 'gemini' && <GeminiMessage text={item.text} />}
{item.type === 'gemini' && (
<GeminiMessage
text={item.text}
isPending={isPending}
availableTerminalHeight={availableTerminalHeight}
/>
)}
{item.type === 'gemini_content' && (
<GeminiMessageContent text={item.text} />
<GeminiMessageContent
text={item.text}
isPending={isPending}
availableTerminalHeight={availableTerminalHeight}
/>
)}
{item.type === 'info' && <InfoMessage text={item.text} />}
{item.type === 'error' && <ErrorMessage text={item.text} />}

View File

@@ -11,9 +11,15 @@ import { Colors } from '../../colors.js';
interface GeminiMessageProps {
text: string;
isPending: boolean;
availableTerminalHeight: number;
}
export const GeminiMessage: React.FC<GeminiMessageProps> = ({ text }) => {
export const GeminiMessage: React.FC<GeminiMessageProps> = ({
text,
isPending,
availableTerminalHeight,
}) => {
const prefix = '✦ ';
const prefixWidth = prefix.length;
@@ -23,7 +29,11 @@ export const GeminiMessage: React.FC<GeminiMessageProps> = ({ text }) => {
<Text color={Colors.AccentPurple}>{prefix}</Text>
</Box>
<Box flexGrow={1} flexDirection="column">
<MarkdownDisplay text={text} />
<MarkdownDisplay
text={text}
isPending={isPending}
availableTerminalHeight={availableTerminalHeight}
/>
</Box>
</Box>
);

View File

@@ -10,6 +10,8 @@ import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
interface GeminiMessageContentProps {
text: string;
isPending: boolean;
availableTerminalHeight: number;
}
/*
@@ -20,13 +22,19 @@ interface GeminiMessageContentProps {
*/
export const GeminiMessageContent: React.FC<GeminiMessageContentProps> = ({
text,
isPending,
availableTerminalHeight,
}) => {
const originalPrefix = '✦ ';
const prefixWidth = originalPrefix.length;
return (
<Box flexDirection="column" paddingLeft={prefixWidth}>
<MarkdownDisplay text={text} />
<MarkdownDisplay
text={text}
isPending={isPending}
availableTerminalHeight={availableTerminalHeight}
/>
</Box>
);
};

View File

@@ -29,7 +29,6 @@ export const ToolGroupMessage: React.FC<ToolGroupMessageProps> = ({
const borderColor = hasPending ? Colors.AccentYellow : Colors.SubtleComment;
const staticHeight = /* border */ 2 + /* marginBottom */ 1;
availableTerminalHeight -= staticHeight;
return (
<Box
@@ -58,7 +57,7 @@ export const ToolGroupMessage: React.FC<ToolGroupMessageProps> = ({
resultDisplay={tool.resultDisplay}
status={tool.status}
confirmationDetails={tool.confirmationDetails}
availableTerminalHeight={availableTerminalHeight}
availableTerminalHeight={availableTerminalHeight - staticHeight}
/>
{tool.status === ToolCallStatus.Confirming &&
tool.confirmationDetails && (

View File

@@ -26,7 +26,6 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({
const statusIndicatorWidth = 3;
const hasResult = resultDisplay && resultDisplay.toString().trim().length > 0;
const staticHeight = /* Header */ 1;
availableTerminalHeight -= staticHeight;
let displayableResult = resultDisplay;
let hiddenLines = 0;
@@ -37,7 +36,7 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({
const lines = resultDisplay.split('\n');
// Estimate available height for this specific tool message content area
// This is a rough estimate; ideally, we'd have a more precise measurement.
const contentHeightEstimate = availableTerminalHeight - 5; // Subtracting lines for tool name, status, padding etc.
const contentHeightEstimate = availableTerminalHeight - staticHeight - 5; // Subtracting lines for tool name, status, padding etc.
if (lines.length > contentHeightEstimate && contentHeightEstimate > 0) {
displayableResult = lines.slice(0, contentHeightEstimate).join('\n');
hiddenLines = lines.length - contentHeightEstimate;
@@ -83,7 +82,11 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({
<Box flexDirection="column">
{typeof displayableResult === 'string' && (
<Box flexDirection="column">
<MarkdownDisplay text={displayableResult} />
<MarkdownDisplay
text={displayableResult}
isPending={false}
availableTerminalHeight={availableTerminalHeight}
/>
</Box>
)}
{typeof displayableResult === 'object' && (