mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-26 14:01:14 -07:00
feat(cli): finalize thinking UI with white unindented Thinking text
This commit is contained in:
@@ -12,7 +12,6 @@ import { StreamingContext } from '../contexts/StreamingContext.js';
|
||||
import { StreamingState } from '../types.js';
|
||||
import { vi } from 'vitest';
|
||||
import * as useTerminalSize from '../hooks/useTerminalSize.js';
|
||||
import * as terminalUtils from '../utils/terminalUtils.js';
|
||||
|
||||
// Mock GeminiRespondingSpinner
|
||||
vi.mock('./GeminiRespondingSpinner.js', () => ({
|
||||
@@ -35,12 +34,7 @@ vi.mock('../hooks/useTerminalSize.js', () => ({
|
||||
useTerminalSize: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../utils/terminalUtils.js', () => ({
|
||||
shouldUseEmoji: vi.fn(() => true),
|
||||
}));
|
||||
|
||||
const useTerminalSizeMock = vi.mocked(useTerminalSize.useTerminalSize);
|
||||
const shouldUseEmojiMock = vi.mocked(terminalUtils.shouldUseEmoji);
|
||||
|
||||
const renderWithContext = (
|
||||
ui: React.ReactElement,
|
||||
@@ -264,34 +258,13 @@ describe('<LoadingIndicator />', () => {
|
||||
const output = lastFrame();
|
||||
expect(output).toBeDefined();
|
||||
if (output) {
|
||||
expect(output).toContain('💬');
|
||||
expect(output).toContain('Thinking... ');
|
||||
expect(output).toContain('Thinking about something...');
|
||||
expect(output).not.toContain('and other stuff.');
|
||||
}
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should use ASCII fallback thought indicator when emoji is unavailable', async () => {
|
||||
shouldUseEmojiMock.mockReturnValue(false);
|
||||
const props = {
|
||||
thought: {
|
||||
subject: 'Thinking with fallback',
|
||||
description: 'details',
|
||||
},
|
||||
elapsedTime: 5,
|
||||
};
|
||||
const { lastFrame, unmount, waitUntilReady } = renderWithContext(
|
||||
<LoadingIndicator {...props} />,
|
||||
StreamingState.Responding,
|
||||
);
|
||||
await waitUntilReady();
|
||||
const output = lastFrame();
|
||||
expect(output).toContain('o Thinking with fallback');
|
||||
expect(output).not.toContain('💬');
|
||||
shouldUseEmojiMock.mockReturnValue(true);
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should prioritize thought.subject over currentLoadingPhrase', async () => {
|
||||
const props = {
|
||||
thought: {
|
||||
@@ -307,13 +280,13 @@ describe('<LoadingIndicator />', () => {
|
||||
);
|
||||
await waitUntilReady();
|
||||
const output = lastFrame();
|
||||
expect(output).toContain('💬');
|
||||
expect(output).toContain('Thinking... ');
|
||||
expect(output).toContain('This should be displayed');
|
||||
expect(output).not.toContain('This should not be displayed');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should not display thought icon for non-thought loading phrases', async () => {
|
||||
it('should not display thought indicator for non-thought loading phrases', async () => {
|
||||
const { lastFrame, unmount, waitUntilReady } = renderWithContext(
|
||||
<LoadingIndicator
|
||||
currentLoadingPhrase="some random tip..."
|
||||
@@ -322,7 +295,7 @@ describe('<LoadingIndicator />', () => {
|
||||
StreamingState.Responding,
|
||||
);
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).not.toContain('💬');
|
||||
expect(lastFrame()).not.toContain('Thinking... ');
|
||||
unmount();
|
||||
});
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import { formatDuration } from '../utils/formatters.js';
|
||||
import { useTerminalSize } from '../hooks/useTerminalSize.js';
|
||||
import { isNarrowWidth } from '../utils/isNarrowWidth.js';
|
||||
import { INTERACTIVE_SHELL_WAITING_PHRASE } from '../hooks/usePhraseCycler.js';
|
||||
import { shouldUseEmoji } from '../utils/terminalUtils.js';
|
||||
|
||||
interface LoadingIndicatorProps {
|
||||
currentLoadingPhrase?: string;
|
||||
@@ -59,9 +58,7 @@ export const LoadingIndicator: React.FC<LoadingIndicatorProps> = ({
|
||||
const hasThoughtIndicator =
|
||||
currentLoadingPhrase !== INTERACTIVE_SHELL_WAITING_PHRASE &&
|
||||
Boolean(thought?.subject?.trim());
|
||||
const thinkingIndicator = hasThoughtIndicator
|
||||
? `${shouldUseEmoji() ? '💬' : 'o'} `
|
||||
: '';
|
||||
const thinkingIndicator = hasThoughtIndicator ? 'Thinking... ' : '';
|
||||
|
||||
const cancelAndTimerContent =
|
||||
showCancelAndTimer &&
|
||||
|
||||
@@ -131,15 +131,14 @@ export const ThinkingMessage: React.FC<ThinkingMessageProps> = ({
|
||||
);
|
||||
|
||||
const fullSummaryDisplayLines = useMemo(
|
||||
() => (fullLines.length > 0 ? wrapLineToWidth(fullLines[0], contentWidth) : []),
|
||||
() =>
|
||||
fullLines.length > 0 ? wrapLineToWidth(fullLines[0], contentWidth) : [],
|
||||
[fullLines, contentWidth],
|
||||
);
|
||||
|
||||
const fullBodyDisplayLines = useMemo(
|
||||
() =>
|
||||
fullLines
|
||||
.slice(1)
|
||||
.flatMap((line) => wrapLineToWidth(line, contentWidth)),
|
||||
fullLines.slice(1).flatMap((line) => wrapLineToWidth(line, contentWidth)),
|
||||
[fullLines, contentWidth],
|
||||
);
|
||||
|
||||
@@ -163,7 +162,7 @@ export const ThinkingMessage: React.FC<ThinkingMessageProps> = ({
|
||||
<>
|
||||
<Text color={theme.text.primary} italic>
|
||||
{' '}
|
||||
Thinking...
|
||||
Thinking...{' '}
|
||||
</Text>
|
||||
<Box flexDirection="row">
|
||||
<Box width={THINKING_LEFT_PADDING} />
|
||||
|
||||
@@ -43,25 +43,3 @@ export function isITerm2(): boolean {
|
||||
export function resetITerm2Cache(): void {
|
||||
cachedIsITerm2 = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the terminal likely supports emoji.
|
||||
*/
|
||||
export function shouldUseEmoji(): boolean {
|
||||
const locale = (
|
||||
process.env['LC_ALL'] ||
|
||||
process.env['LC_CTYPE'] ||
|
||||
process.env['LANG'] ||
|
||||
''
|
||||
).toLowerCase();
|
||||
const supportsUtf8 = locale.includes('utf-8') || locale.includes('utf8');
|
||||
if (!supportsUtf8) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (process.env['TERM'] === 'linux') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user