summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/shellCommandProcessor.ts
diff options
context:
space:
mode:
authorOlcan <[email protected]>2025-05-21 13:16:50 -0700
committerGitHub <[email protected]>2025-05-21 13:16:50 -0700
commit00ab1905e0b252a70e2171b3f83d36adb7fec250 (patch)
tree21e3ccdb906bb411da7f78bd19882bc2d91edde2 /packages/cli/src/ui/hooks/shellCommandProcessor.ts
parent01dbc61d1cad13901b83f0b3a75827f209119394 (diff)
use pending history item for shell mode, update as output is received (#471)
Diffstat (limited to 'packages/cli/src/ui/hooks/shellCommandProcessor.ts')
-rw-r--r--packages/cli/src/ui/hooks/shellCommandProcessor.ts30
1 files changed, 24 insertions, 6 deletions
diff --git a/packages/cli/src/ui/hooks/shellCommandProcessor.ts b/packages/cli/src/ui/hooks/shellCommandProcessor.ts
index 9ad5ef03..e7ccefcd 100644
--- a/packages/cli/src/ui/hooks/shellCommandProcessor.ts
+++ b/packages/cli/src/ui/hooks/shellCommandProcessor.ts
@@ -5,6 +5,7 @@
*/
import { spawn } from 'child_process';
+import type { HistoryItemWithoutId } from '../types.js';
import type { exec as ExecType } from 'child_process';
import { useCallback } from 'react';
import { Config } from '@gemini-code/server';
@@ -21,6 +22,9 @@ import fs from 'fs';
*/
export const useShellCommandProcessor = (
addItemToHistory: UseHistoryManagerReturn['addItem'],
+ setPendingHistoryItem: React.Dispatch<
+ React.SetStateAction<HistoryItemWithoutId | null>
+ >,
onExec: (command: Promise<void>) => void,
onDebugMessage: (message: string) => void,
config: Config,
@@ -115,18 +119,25 @@ export const useShellCommandProcessor = (
cwd: targetDir,
stdio: ['ignore', 'pipe', 'pipe'],
});
+
let output = '';
- child.stdout.on('data', (data) => {
- output += data;
- });
- child.stderr.on('data', (data) => {
+ const handleOutput = (data: string) => {
output += data;
- });
+ setPendingHistoryItem({
+ type: 'info',
+ text: output,
+ });
+ };
+ child.stdout.on('data', handleOutput);
+ child.stderr.on('data', handleOutput);
+
let error: Error | null = null;
child.on('error', (err: Error) => {
error = err;
});
+
child.on('close', (code, signal) => {
+ setPendingHistoryItem(null);
output = output.trim() || '(Command produced no output)';
if (error) {
const text = `${error.message.replace(commandToExecute, rawQuery)}\n${output}`;
@@ -169,7 +180,14 @@ export const useShellCommandProcessor = (
return true; // Command was initiated
},
- [config, onDebugMessage, addItemToHistory, onExec, executeCommand],
+ [
+ config,
+ onDebugMessage,
+ addItemToHistory,
+ setPendingHistoryItem,
+ onExec,
+ executeCommand,
+ ],
);
return { handleShellCommand };