From d061419452e1faeb3cc43d1aa5d21dfc799f36dd Mon Sep 17 00:00:00 2001 From: Olcan Date: Sun, 8 Jun 2025 17:11:16 -0700 Subject: [PATCH] enforce minimum lines shown/hidden (#860) --- .../cli/src/ui/components/messages/ToolMessage.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/ui/components/messages/ToolMessage.tsx b/packages/cli/src/ui/components/messages/ToolMessage.tsx index 3883d361..230f651c 100644 --- a/packages/cli/src/ui/components/messages/ToolMessage.tsx +++ b/packages/cli/src/ui/components/messages/ToolMessage.tsx @@ -15,6 +15,8 @@ import { GeminiRespondingSpinner } from '../GeminiRespondingSpinner.js'; const STATIC_HEIGHT = 1; const RESERVED_LINE_COUNT = 5; // for tool name, status, padding etc. const STATUS_INDICATOR_WIDTH = 3; +const MIN_LINES_SHOWN = 2; // show at least this many lines +const MIN_LINES_HIDDEN = 3; // hide at least this many lines (or don't hide any) export type TextEmphasis = 'high' | 'medium' | 'low'; @@ -33,14 +35,20 @@ export const ToolMessage: React.FC = ({ emphasis = 'medium', renderOutputAsMarkdown = true, }) => { - const contentHeightEstimate = - availableTerminalHeight - STATIC_HEIGHT - RESERVED_LINE_COUNT; const resultIsString = typeof resultDisplay === 'string' && resultDisplay.trim().length > 0; const lines = React.useMemo( () => (resultIsString ? resultDisplay.split('\n') : []), [resultIsString, resultDisplay], ); + let contentHeightEstimate = Math.max( + availableTerminalHeight - STATIC_HEIGHT - RESERVED_LINE_COUNT, + MIN_LINES_SHOWN + 1, // enforce minimum lines shown + ); + // enforce minimum lines hidden (don't hide any otherwise) + if (lines.length - contentHeightEstimate < MIN_LINES_HIDDEN) { + contentHeightEstimate = lines.length; + } // Truncate the overall string content if it's too long. // MarkdownRenderer will handle specific truncation for code blocks within this content. @@ -53,7 +61,7 @@ export const ToolMessage: React.FC = ({ : resultDisplay, [lines, resultIsString, contentHeightEstimate, resultDisplay], ); - const hiddenLines = lines.length - contentHeightEstimate; + const hiddenLines = Math.max(0, lines.length - contentHeightEstimate); return (