Highlight slash commands in history (#5323)
This commit is contained in:
parent
61e382444a
commit
6f7beb414c
|
@ -35,6 +35,18 @@ describe('<HistoryItemDisplay />', () => {
|
||||||
expect(lastFrame()).toContain('Hello');
|
expect(lastFrame()).toContain('Hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders UserMessage for "user" type with slash command', () => {
|
||||||
|
const item: HistoryItem = {
|
||||||
|
...baseItem,
|
||||||
|
type: MessageType.USER,
|
||||||
|
text: '/theme',
|
||||||
|
};
|
||||||
|
const { lastFrame } = render(
|
||||||
|
<HistoryItemDisplay {...baseItem} item={item} />,
|
||||||
|
);
|
||||||
|
expect(lastFrame()).toContain('/theme');
|
||||||
|
});
|
||||||
|
|
||||||
it('renders StatsDisplay for "stats" type', () => {
|
it('renders StatsDisplay for "stats" type', () => {
|
||||||
const item: HistoryItem = {
|
const item: HistoryItem = {
|
||||||
...baseItem,
|
...baseItem,
|
||||||
|
|
|
@ -15,11 +15,15 @@ interface UserMessageProps {
|
||||||
export const UserMessage: React.FC<UserMessageProps> = ({ text }) => {
|
export const UserMessage: React.FC<UserMessageProps> = ({ text }) => {
|
||||||
const prefix = '> ';
|
const prefix = '> ';
|
||||||
const prefixWidth = prefix.length;
|
const prefixWidth = prefix.length;
|
||||||
|
const isSlashCommand = text.startsWith('/');
|
||||||
|
|
||||||
|
const textColor = isSlashCommand ? Colors.AccentPurple : Colors.Gray;
|
||||||
|
const borderColor = isSlashCommand ? Colors.AccentPurple : Colors.Gray;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
borderStyle="round"
|
borderStyle="round"
|
||||||
borderColor={Colors.Gray}
|
borderColor={borderColor}
|
||||||
flexDirection="row"
|
flexDirection="row"
|
||||||
paddingX={2}
|
paddingX={2}
|
||||||
paddingY={0}
|
paddingY={0}
|
||||||
|
@ -27,10 +31,10 @@ export const UserMessage: React.FC<UserMessageProps> = ({ text }) => {
|
||||||
alignSelf="flex-start"
|
alignSelf="flex-start"
|
||||||
>
|
>
|
||||||
<Box width={prefixWidth}>
|
<Box width={prefixWidth}>
|
||||||
<Text color={Colors.Gray}>{prefix}</Text>
|
<Text color={textColor}>{prefix}</Text>
|
||||||
</Box>
|
</Box>
|
||||||
<Box flexGrow={1}>
|
<Box flexGrow={1}>
|
||||||
<Text wrap="wrap" color={Colors.Gray}>
|
<Text wrap="wrap" color={textColor}>
|
||||||
{text}
|
{text}
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
Loading…
Reference in New Issue