mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 21:03:05 -07:00
fix(ux): have user message display a short path for pasted images (#17613)
This commit is contained in:
@@ -44,4 +44,16 @@ describe('UserMessage', () => {
|
|||||||
|
|
||||||
expect(output).toMatchSnapshot();
|
expect(output).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transforms image paths in user message', () => {
|
||||||
|
const message = 'Check out this image: @/path/to/my-image.png';
|
||||||
|
const { lastFrame } = renderWithProviders(
|
||||||
|
<UserMessage text={message} width={80} />,
|
||||||
|
{ width: 80 },
|
||||||
|
);
|
||||||
|
const output = lastFrame();
|
||||||
|
|
||||||
|
expect(output).toContain('[Image my-image.png]');
|
||||||
|
expect(output).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,10 +5,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
|
import { useMemo } from 'react';
|
||||||
import { Text, Box } from 'ink';
|
import { Text, Box } from 'ink';
|
||||||
import { theme } from '../../semantic-colors.js';
|
import { theme } from '../../semantic-colors.js';
|
||||||
import { SCREEN_READER_USER_PREFIX } from '../../textConstants.js';
|
import { SCREEN_READER_USER_PREFIX } from '../../textConstants.js';
|
||||||
import { isSlashCommand as checkIsSlashCommand } from '../../utils/commandUtils.js';
|
import { isSlashCommand as checkIsSlashCommand } from '../../utils/commandUtils.js';
|
||||||
|
import {
|
||||||
|
calculateTransformationsForLine,
|
||||||
|
calculateTransformedLine,
|
||||||
|
} from '../shared/text-buffer.js';
|
||||||
import { HalfLinePaddedBox } from '../shared/HalfLinePaddedBox.js';
|
import { HalfLinePaddedBox } from '../shared/HalfLinePaddedBox.js';
|
||||||
import { DEFAULT_BACKGROUND_OPACITY } from '../../constants.js';
|
import { DEFAULT_BACKGROUND_OPACITY } from '../../constants.js';
|
||||||
import { useConfig } from '../../contexts/ConfigContext.js';
|
import { useConfig } from '../../contexts/ConfigContext.js';
|
||||||
@@ -27,6 +32,24 @@ export const UserMessage: React.FC<UserMessageProps> = ({ text, width }) => {
|
|||||||
|
|
||||||
const textColor = isSlashCommand ? theme.text.accent : theme.text.secondary;
|
const textColor = isSlashCommand ? theme.text.accent : theme.text.secondary;
|
||||||
|
|
||||||
|
const displayText = useMemo(() => {
|
||||||
|
if (!text) return text;
|
||||||
|
return text
|
||||||
|
.split('\n')
|
||||||
|
.map((line) => {
|
||||||
|
const transformations = calculateTransformationsForLine(line);
|
||||||
|
// We pass a cursor position of [-1, -1] so that no transformations are expanded (e.g. images remain collapsed)
|
||||||
|
const { transformedLine } = calculateTransformedLine(
|
||||||
|
line,
|
||||||
|
0, // line index doesn't matter since cursor is [-1, -1]
|
||||||
|
[-1, -1],
|
||||||
|
transformations,
|
||||||
|
);
|
||||||
|
return transformedLine;
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
}, [text]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HalfLinePaddedBox
|
<HalfLinePaddedBox
|
||||||
backgroundBaseColor={theme.border.default}
|
backgroundBaseColor={theme.border.default}
|
||||||
@@ -51,7 +74,7 @@ export const UserMessage: React.FC<UserMessageProps> = ({ text, width }) => {
|
|||||||
</Box>
|
</Box>
|
||||||
<Box flexGrow={1}>
|
<Box flexGrow={1}>
|
||||||
<Text wrap="wrap" color={textColor}>
|
<Text wrap="wrap" color={textColor}>
|
||||||
{text}
|
{displayText}
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -18,3 +18,9 @@ exports[`UserMessage > renders slash command message 1`] = `
|
|||||||
> /help
|
> /help
|
||||||
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄"
|
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`UserMessage > transforms image paths in user message 1`] = `
|
||||||
|
"▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
|
||||||
|
> Check out this image: [Image my-image.png]
|
||||||
|
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄"
|
||||||
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user