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

47 lines
1.2 KiB
TypeScript
Raw Normal View History

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
2025-04-15 21:41:08 -07:00
import React from 'react';
import { Text, Box } from 'ink';
import { MarkdownRenderer } from '../../utils/MarkdownRenderer.js';
2025-04-19 12:38:09 -04:00
import { Colors } from '../../colors.js';
2025-04-15 21:41:08 -07:00
interface GeminiMessageProps {
2025-04-17 18:06:21 -04:00
text: string;
2025-04-15 21:41:08 -07:00
}
2025-04-18 19:09:41 -04:00
export const GeminiMessage: React.FC<GeminiMessageProps> = ({ text }) => {
2025-04-17 18:06:21 -04:00
const prefix = '✦ ';
const prefixWidth = prefix.length;
2025-04-15 21:41:08 -07:00
2025-04-17 18:06:21 -04:00
// Handle potentially null or undefined text gracefully
const safeText = text || '';
2025-04-15 21:41:08 -07:00
2025-04-17 18:06:21 -04:00
// Use the static render method from the MarkdownRenderer class
// Pass safeText which is guaranteed to be a string
const renderedBlocks = MarkdownRenderer.render(safeText);
2025-04-15 21:41:08 -07:00
2025-04-17 18:06:21 -04:00
// If the original text was actually empty/null, render the minimal state
if (!safeText && renderedBlocks.length === 0) {
2025-04-15 21:41:08 -07:00
return (
2025-04-17 18:06:21 -04:00
<Box flexDirection="row">
<Box width={prefixWidth}>
2025-04-19 12:38:09 -04:00
<Text color={Colors.AccentPurple}>{prefix}</Text>
2025-04-15 21:41:08 -07:00
</Box>
2025-04-17 18:06:21 -04:00
<Box flexGrow={1}></Box>
</Box>
2025-04-15 21:41:08 -07:00
);
2025-04-17 18:06:21 -04:00
}
return (
<Box flexDirection="row">
<Box flexGrow={1} flexDirection="column">
{renderedBlocks}
</Box>
</Box>
);
2025-04-15 21:41:08 -07:00
};