Files
gemini-cli/packages/cli/src/ui/components/messages/GeminiMessage.tsx
T

65 lines
1.8 KiB
TypeScript
Raw Normal View History

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type React from 'react';
2025-04-15 21:41:08 -07:00
import { Text, Box } from 'ink';
import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
import { ShowMoreLines } from '../ShowMoreLines.js';
2025-09-10 10:57:07 -07:00
import { theme } from '../../semantic-colors.js';
2025-08-28 20:52:14 +00:00
import { SCREEN_READER_MODEL_PREFIX } from '../../textConstants.js';
import { useUIState } from '../../contexts/UIStateContext.js';
2025-11-11 07:50:11 -08:00
import { useAlternateBuffer } from '../../hooks/useAlternateBuffer.js';
2025-04-15 21:41:08 -07:00
interface GeminiMessageProps {
2025-04-17 18:06:21 -04:00
text: string;
isPending: boolean;
availableTerminalHeight?: number;
terminalWidth: number;
2025-04-15 21:41:08 -07:00
}
export const GeminiMessage: React.FC<GeminiMessageProps> = ({
text,
isPending,
availableTerminalHeight,
terminalWidth,
}) => {
const { renderMarkdown } = useUIState();
2025-04-17 18:06:21 -04:00
const prefix = '✦ ';
const prefixWidth = prefix.length;
2025-11-11 07:50:11 -08:00
const isAlternateBuffer = useAlternateBuffer();
2025-04-17 18:06:21 -04:00
return (
<Box flexDirection="row">
2025-04-22 07:48:12 -04:00
<Box width={prefixWidth}>
2025-09-10 10:57:07 -07:00
<Text color={theme.text.accent} aria-label={SCREEN_READER_MODEL_PREFIX}>
{prefix}
</Text>
2025-04-22 07:48:12 -04:00
</Box>
2025-04-17 18:06:21 -04:00
<Box flexGrow={1} flexDirection="column">
<MarkdownDisplay
text={text}
isPending={isPending}
2025-11-11 07:50:11 -08:00
availableTerminalHeight={
isAlternateBuffer || availableTerminalHeight === undefined
? undefined
: Math.max(availableTerminalHeight - 1, 1)
2025-11-11 07:50:11 -08:00
}
terminalWidth={terminalWidth}
renderMarkdown={renderMarkdown}
/>
<Box
marginTop={isAlternateBuffer ? 0 : 1}
marginBottom={isAlternateBuffer ? 1 : 0}
>
<ShowMoreLines
constrainHeight={availableTerminalHeight !== undefined}
/>
</Box>
2025-04-17 18:06:21 -04:00
</Box>
</Box>
);
2025-04-15 21:41:08 -07:00
};