summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/shellCommandProcessor.ts
diff options
context:
space:
mode:
authorOlcan <[email protected]>2025-05-30 00:02:30 -0700
committerGitHub <[email protected]>2025-05-30 00:02:30 -0700
commitb0aeeb53b101ed73dfebbff74197efdc4e18b142 (patch)
tree3eed5731b4244766cbd4e1b770eb7f869a73a90d /packages/cli/src/ui/hooks/shellCommandProcessor.ts
parent2582c20e2a541b0a90d9f62754c7008af13c194f (diff)
update shell output at an interval to reduce flicker (#614)
Diffstat (limited to 'packages/cli/src/ui/hooks/shellCommandProcessor.ts')
-rw-r--r--packages/cli/src/ui/hooks/shellCommandProcessor.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/packages/cli/src/ui/hooks/shellCommandProcessor.ts b/packages/cli/src/ui/hooks/shellCommandProcessor.ts
index 74dade5e..59e337b4 100644
--- a/packages/cli/src/ui/hooks/shellCommandProcessor.ts
+++ b/packages/cli/src/ui/hooks/shellCommandProcessor.ts
@@ -16,6 +16,8 @@ import path from 'path';
import os from 'os';
import fs from 'fs';
+const OUTPUT_UPDATE_INTERVAL_MS = 1000;
+
/**
* Hook to process shell commands (e.g., !ls, $pwd).
* Executes the command in the target directory and adds output/errors to history.
@@ -122,16 +124,20 @@ export const useShellCommandProcessor = (
let exited = false;
let output = '';
+ let lastUpdateTime = Date.now();
const handleOutput = (data: string) => {
// continue to consume post-exit for background processes
// removing listeners can overflow OS buffer and block subprocesses
// destroying (e.g. child.stdout.destroy()) can terminate subprocesses via SIGPIPE
if (!exited) {
output += data;
- setPendingHistoryItem({
- type: 'info',
- text: output,
- });
+ if (Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS) {
+ setPendingHistoryItem({
+ type: 'info',
+ text: output,
+ });
+ lastUpdateTime = Date.now();
+ }
}
};
child.stdout.on('data', handleOutput);