2025-04-18 17:44:24 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-26 00:04:53 +02:00
|
|
|
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';
|
2025-08-26 11:51:27 +08:00
|
|
|
import { isSlashCommand as checkIsSlashCommand } from '../../utils/commandUtils.js';
|
2025-04-15 21:41:08 -07:00
|
|
|
|
|
|
|
|
interface UserMessageProps {
|
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 UserMessage: React.FC<UserMessageProps> = ({ text }) => {
|
2025-04-17 18:06:21 -04:00
|
|
|
const prefix = '> ';
|
|
|
|
|
const prefixWidth = prefix.length;
|
2025-08-26 11:51:27 +08:00
|
|
|
const isSlashCommand = checkIsSlashCommand(text);
|
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;
|
|
|
|
|
const borderColor = isSlashCommand ? theme.text.accent : theme.text.secondary;
|
2025-04-15 21:41:08 -07:00
|
|
|
|
2025-04-17 18:06:21 -04:00
|
|
|
return (
|
2025-06-30 00:28:56 +01:00
|
|
|
<Box
|
|
|
|
|
borderStyle="round"
|
2025-07-31 16:24:23 -07:00
|
|
|
borderColor={borderColor}
|
2025-06-30 00:28:56 +01:00
|
|
|
flexDirection="row"
|
|
|
|
|
paddingX={2}
|
|
|
|
|
paddingY={0}
|
|
|
|
|
marginY={1}
|
|
|
|
|
alignSelf="flex-start"
|
|
|
|
|
>
|
2025-04-17 18:06:21 -04:00
|
|
|
<Box width={prefixWidth}>
|
2025-08-21 22:29:15 +00:00
|
|
|
<Text color={textColor} aria-label={SCREEN_READER_USER_PREFIX}>
|
|
|
|
|
{prefix}
|
|
|
|
|
</Text>
|
2025-04-17 18:06:21 -04:00
|
|
|
</Box>
|
|
|
|
|
<Box flexGrow={1}>
|
2025-07-31 16:24:23 -07:00
|
|
|
<Text wrap="wrap" color={textColor}>
|
2025-04-22 07:48:12 -04:00
|
|
|
{text}
|
|
|
|
|
</Text>
|
2025-04-17 18:06:21 -04:00
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
2025-04-15 21:41:08 -07:00
|
|
|
};
|