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

61 lines
1.7 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';
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_USER_PREFIX } from '../../textConstants.js';
import { isSlashCommand as checkIsSlashCommand } from '../../utils/commandUtils.js';
import { HalfLinePaddedBox } from '../shared/HalfLinePaddedBox.js';
import { DEFAULT_BACKGROUND_OPACITY } from '../../constants.js';
import { useConfig } from '../../contexts/ConfigContext.js';
2025-04-15 21:41:08 -07:00
interface UserMessageProps {
2025-04-17 18:06:21 -04:00
text: string;
2025-11-11 07:50:11 -08:00
width: number;
2025-04-15 21:41:08 -07:00
}
2025-11-11 07:50:11 -08:00
export const UserMessage: React.FC<UserMessageProps> = ({ text, width }) => {
2025-04-17 18:06:21 -04:00
const prefix = '> ';
const prefixWidth = prefix.length;
const isSlashCommand = checkIsSlashCommand(text);
const config = useConfig();
const useBackgroundColor = config.getUseBackgroundColor();
2025-07-31 16:24:23 -07:00
2025-09-10 10:57:07 -07:00
const textColor = isSlashCommand ? theme.text.accent : theme.text.secondary;
2025-04-15 21:41:08 -07:00
2025-04-17 18:06:21 -04:00
return (
<HalfLinePaddedBox
backgroundBaseColor={theme.border.default}
backgroundOpacity={DEFAULT_BACKGROUND_OPACITY}
useBackgroundColor={useBackgroundColor}
2025-11-11 07:50:11 -08:00
>
<Box
flexDirection="row"
paddingY={0}
marginY={useBackgroundColor ? 0 : 1}
paddingX={useBackgroundColor ? 1 : 0}
alignSelf="flex-start"
width={width}
>
<Box width={prefixWidth} flexShrink={0}>
<Text
color={theme.text.accent}
aria-label={SCREEN_READER_USER_PREFIX}
>
{prefix}
</Text>
</Box>
<Box flexGrow={1}>
<Text wrap="wrap" color={textColor}>
{text}
</Text>
</Box>
2025-04-17 18:06:21 -04:00
</Box>
</HalfLinePaddedBox>
2025-04-17 18:06:21 -04:00
);
2025-04-15 21:41:08 -07:00
};