mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-30 06:54:15 -07:00
move stdio (#13528)
This commit is contained in:
@@ -40,6 +40,28 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
|||||||
return {
|
return {
|
||||||
...actual,
|
...actual,
|
||||||
recordSlowRender: vi.fn(),
|
recordSlowRender: vi.fn(),
|
||||||
|
writeToStdout: vi.fn((...args) =>
|
||||||
|
process.stdout.write(
|
||||||
|
...(args as Parameters<typeof process.stdout.write>),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
patchStdio: vi.fn(() => () => {}),
|
||||||
|
createInkStdio: vi.fn(() => ({
|
||||||
|
stdout: {
|
||||||
|
write: vi.fn((...args) =>
|
||||||
|
process.stdout.write(
|
||||||
|
...(args as Parameters<typeof process.stdout.write>),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
columns: 80,
|
||||||
|
rows: 24,
|
||||||
|
on: vi.fn(),
|
||||||
|
removeListener: vi.fn(),
|
||||||
|
},
|
||||||
|
stderr: {
|
||||||
|
write: vi.fn(),
|
||||||
|
},
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -149,35 +171,6 @@ vi.mock('./ui/utils/mouse.js', () => ({
|
|||||||
isIncompleteMouseSequence: vi.fn(),
|
isIncompleteMouseSequence: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('./utils/stdio.js', async (importOriginal) => {
|
|
||||||
const actual = await importOriginal<typeof import('./utils/stdio.js')>();
|
|
||||||
return {
|
|
||||||
...actual,
|
|
||||||
writeToStdout: vi.fn((...args) =>
|
|
||||||
process.stdout.write(
|
|
||||||
...(args as Parameters<typeof process.stdout.write>),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
patchStdio: vi.fn(() => () => {}),
|
|
||||||
createInkStdio: vi.fn(() => ({
|
|
||||||
stdout: {
|
|
||||||
write: vi.fn((...args) =>
|
|
||||||
process.stdout.write(
|
|
||||||
...(args as Parameters<typeof process.stdout.write>),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
columns: 80,
|
|
||||||
rows: 24,
|
|
||||||
on: vi.fn(),
|
|
||||||
removeListener: vi.fn(),
|
|
||||||
},
|
|
||||||
stderr: {
|
|
||||||
write: vi.fn(),
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('gemini.tsx main function', () => {
|
describe('gemini.tsx main function', () => {
|
||||||
let originalEnvGeminiSandbox: string | undefined;
|
let originalEnvGeminiSandbox: string | undefined;
|
||||||
let originalEnvSandbox: string | undefined;
|
let originalEnvSandbox: string | undefined;
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ import {
|
|||||||
recordSlowRender,
|
recordSlowRender,
|
||||||
coreEvents,
|
coreEvents,
|
||||||
CoreEvent,
|
CoreEvent,
|
||||||
|
createInkStdio,
|
||||||
|
patchStdio,
|
||||||
|
writeToStdout,
|
||||||
|
writeToStderr,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import {
|
import {
|
||||||
initializeApp,
|
initializeApp,
|
||||||
@@ -85,12 +89,6 @@ import { disableMouseEvents, enableMouseEvents } from './ui/utils/mouse.js';
|
|||||||
import { ScrollProvider } from './ui/contexts/ScrollProvider.js';
|
import { ScrollProvider } from './ui/contexts/ScrollProvider.js';
|
||||||
import ansiEscapes from 'ansi-escapes';
|
import ansiEscapes from 'ansi-escapes';
|
||||||
import { isAlternateBufferEnabled } from './ui/hooks/useAlternateBuffer.js';
|
import { isAlternateBufferEnabled } from './ui/hooks/useAlternateBuffer.js';
|
||||||
import {
|
|
||||||
createInkStdio,
|
|
||||||
patchStdio,
|
|
||||||
writeToStderr,
|
|
||||||
writeToStdout,
|
|
||||||
} from './utils/stdio.js';
|
|
||||||
|
|
||||||
import { profiler } from './ui/components/DebugProfiler.js';
|
import { profiler } from './ui/components/DebugProfiler.js';
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,21 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
|||||||
...actual,
|
...actual,
|
||||||
coreEvents: mockCoreEvents,
|
coreEvents: mockCoreEvents,
|
||||||
IdeClient: mockIdeClient,
|
IdeClient: mockIdeClient,
|
||||||
|
writeToStdout: vi.fn((...args) =>
|
||||||
|
process.stdout.write(
|
||||||
|
...(args as Parameters<typeof process.stdout.write>),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
writeToStderr: vi.fn((...args) =>
|
||||||
|
process.stderr.write(
|
||||||
|
...(args as Parameters<typeof process.stderr.write>),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
patchStdio: vi.fn(() => () => {}),
|
||||||
|
createInkStdio: vi.fn(() => ({
|
||||||
|
stdout: process.stdout,
|
||||||
|
stderr: process.stderr,
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
import type { LoadedSettings } from '../config/settings.js';
|
import type { LoadedSettings } from '../config/settings.js';
|
||||||
@@ -126,19 +141,6 @@ vi.mock('./utils/mouse.js', () => ({
|
|||||||
enableMouseEvents: vi.fn(),
|
enableMouseEvents: vi.fn(),
|
||||||
disableMouseEvents: vi.fn(),
|
disableMouseEvents: vi.fn(),
|
||||||
}));
|
}));
|
||||||
vi.mock('../utils/stdio.js', () => ({
|
|
||||||
writeToStdout: vi.fn((...args) =>
|
|
||||||
process.stdout.write(...(args as Parameters<typeof process.stdout.write>)),
|
|
||||||
),
|
|
||||||
writeToStderr: vi.fn((...args) =>
|
|
||||||
process.stderr.write(...(args as Parameters<typeof process.stderr.write>)),
|
|
||||||
),
|
|
||||||
patchStdio: vi.fn(() => () => {}),
|
|
||||||
createInkStdio: vi.fn(() => ({
|
|
||||||
stdout: process.stdout,
|
|
||||||
stderr: process.stderr,
|
|
||||||
})),
|
|
||||||
}));
|
|
||||||
|
|
||||||
import { useHistory } from './hooks/useHistoryManager.js';
|
import { useHistory } from './hooks/useHistoryManager.js';
|
||||||
import { useThemeCommand } from './hooks/useThemeCommand.js';
|
import { useThemeCommand } from './hooks/useThemeCommand.js';
|
||||||
@@ -163,10 +165,9 @@ import { useLoadingIndicator } from './hooks/useLoadingIndicator.js';
|
|||||||
import { useKeypress, type Key } from './hooks/useKeypress.js';
|
import { useKeypress, type Key } from './hooks/useKeypress.js';
|
||||||
import { measureElement } from 'ink';
|
import { measureElement } from 'ink';
|
||||||
import { useTerminalSize } from './hooks/useTerminalSize.js';
|
import { useTerminalSize } from './hooks/useTerminalSize.js';
|
||||||
import { ShellExecutionService } from '@google/gemini-cli-core';
|
import { ShellExecutionService, writeToStdout } from '@google/gemini-cli-core';
|
||||||
import { type ExtensionManager } from '../config/extension-manager.js';
|
import { type ExtensionManager } from '../config/extension-manager.js';
|
||||||
import { enableMouseEvents, disableMouseEvents } from './utils/mouse.js';
|
import { enableMouseEvents, disableMouseEvents } from './utils/mouse.js';
|
||||||
import { writeToStdout } from '../utils/stdio.js';
|
|
||||||
|
|
||||||
describe('AppContainer State Management', () => {
|
describe('AppContainer State Management', () => {
|
||||||
let mockConfig: Config;
|
let mockConfig: Config;
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ import { disableMouseEvents, enableMouseEvents } from './utils/mouse.js';
|
|||||||
import { useAlternateBuffer } from './hooks/useAlternateBuffer.js';
|
import { useAlternateBuffer } from './hooks/useAlternateBuffer.js';
|
||||||
import { useSettings } from './contexts/SettingsContext.js';
|
import { useSettings } from './contexts/SettingsContext.js';
|
||||||
import { enableSupportedProtocol } from './utils/kittyProtocolDetector.js';
|
import { enableSupportedProtocol } from './utils/kittyProtocolDetector.js';
|
||||||
import { writeToStdout } from '../utils/stdio.js';
|
import { writeToStdout } from '@google/gemini-cli-core';
|
||||||
|
|
||||||
const WARNING_PROMPT_DURATION_MS = 1000;
|
const WARNING_PROMPT_DURATION_MS = 1000;
|
||||||
const QUEUE_ERROR_DISPLAY_DURATION_MS = 3000;
|
const QUEUE_ERROR_DISPLAY_DURATION_MS = 3000;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { writeToStdout } from '../../utils/stdio.js';
|
import { writeToStdout } from '@google/gemini-cli-core';
|
||||||
|
|
||||||
const ENABLE_BRACKETED_PASTE = '\x1b[?2004h';
|
const ENABLE_BRACKETED_PASTE = '\x1b[?2004h';
|
||||||
const DISABLE_BRACKETED_PASTE = '\x1b[?2004l';
|
const DISABLE_BRACKETED_PASTE = '\x1b[?2004l';
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { writeToStdout } from '../../utils/stdio.js';
|
import { writeToStdout } from '@google/gemini-cli-core';
|
||||||
import {
|
import {
|
||||||
SGR_MOUSE_REGEX,
|
SGR_MOUSE_REGEX,
|
||||||
X11_MOUSE_REGEX,
|
X11_MOUSE_REGEX,
|
||||||
|
|||||||
@@ -144,3 +144,6 @@ export * from './test-utils/index.js';
|
|||||||
|
|
||||||
// Export hook types
|
// Export hook types
|
||||||
export * from './hooks/types.js';
|
export * from './hooks/types.js';
|
||||||
|
|
||||||
|
// Export stdio utils
|
||||||
|
export * from './utils/stdio.js';
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||||
import { patchStdio, createInkStdio } from './stdio.js';
|
import { patchStdio, createInkStdio } from './stdio.js';
|
||||||
import { coreEvents } from '@google/gemini-cli-core';
|
import { coreEvents } from './events.js';
|
||||||
|
|
||||||
vi.mock('@google/gemini-cli-core', () => ({
|
vi.mock('./events.js', () => ({
|
||||||
coreEvents: {
|
coreEvents: {
|
||||||
emitOutput: vi.fn(),
|
emitOutput: vi.fn(),
|
||||||
},
|
},
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { coreEvents } from '@google/gemini-cli-core';
|
import { coreEvents } from './events.js';
|
||||||
|
|
||||||
// Capture the original stdout and stderr write methods before any monkey patching occurs.
|
// Capture the original stdout and stderr write methods before any monkey patching occurs.
|
||||||
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
||||||
Reference in New Issue
Block a user