Skip to content

Commit 65bd523

Browse files
committed
Fix output limiting
1 parent a643697 commit 65bd523

File tree

1 file changed

+48
-36
lines changed

1 file changed

+48
-36
lines changed

Diff for: src/CommandExecutor.ts

+48-36
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@ class CommandExecutor {
77
async isProcessing(): Promise<boolean> {
88
const ascript = `
99
tell application "iTerm2"
10-
activate
11-
if windows is equal to {} then
12-
create window with default profile
13-
end if
14-
1510
tell front window
16-
if current session of current tab is missing value then
17-
create tab with default profile
18-
end if
19-
2011
tell current session of current tab
2112
return is processing
2213
end tell
@@ -28,53 +19,74 @@ class CommandExecutor {
2819
const { stdout } = await execPromise(`osascript -e '${ascript}'`);
2920
return stdout.trim() === 'true';
3021
} catch (error) {
22+
console.error('Processing check error:', error);
3123
throw new Error(`Failed to check processing status: ${error}`);
3224
}
3325
}
3426

3527
async executeCommand(command: string): Promise<string> {
36-
const ascript = `
28+
// First get the current contents
29+
const getInitialContent = `
3730
tell application "iTerm2"
38-
activate
39-
if windows is equal to {} then
40-
create window with default profile
41-
end if
42-
4331
tell front window
44-
if current session of current tab is missing value then
45-
create tab with default profile
46-
end if
47-
4832
tell current session of current tab
49-
write text "${command.replace(/"/g, '\\"')}"
33+
set initialContent to contents
34+
return initialContent
5035
end tell
5136
end tell
5237
end tell
5338
`;
5439

55-
await execPromise(`osascript -e '${ascript}'`);
56-
57-
// Wait until command completes
58-
while (await this.isProcessing()) {
59-
await new Promise(resolve => setTimeout(resolve, 100));
60-
}
61-
62-
// Get final output, but only the visible rows
63-
const getOutput = `
40+
const { stdout: initialContent } = await execPromise(`osascript -e '${getInitialContent}'`);
41+
const initialLength = initialContent.length;
42+
43+
// Execute the command
44+
const ascript = `
6445
tell application "iTerm2"
6546
tell front window
6647
tell current session of current tab
67-
set rowCount to number of rows
68-
set contentText to contents
69-
set visibleContent to text 1 thru (rowCount * 200) of contentText
70-
return visibleContent
48+
write text "${command.replace(/"/g, '\\"')}"
7149
end tell
7250
end tell
7351
end tell
7452
`;
75-
76-
const { stdout } = await execPromise(`osascript -e '${getOutput}'`);
77-
return stdout;
53+
54+
try {
55+
await execPromise(`osascript -e '${ascript}'`);
56+
57+
// Wait until command completes
58+
let retryCount = 0;
59+
while (await this.isProcessing()) {
60+
if (retryCount > 100) { // 10 second timeout
61+
throw new Error('Command execution timed out');
62+
}
63+
await new Promise(resolve => setTimeout(resolve, 100));
64+
retryCount++;
65+
}
66+
67+
// Give a small delay for output to settle
68+
await new Promise(resolve => setTimeout(resolve, 200));
69+
70+
// Get final content
71+
const getFinalContent = `
72+
tell application "iTerm2"
73+
tell front window
74+
tell current session of current tab
75+
return contents
76+
end tell
77+
end tell
78+
end tell
79+
`;
80+
81+
const { stdout: finalContent } = await execPromise(`osascript -e '${getFinalContent}'`);
82+
83+
// Return only the new content
84+
return finalContent.substring(initialLength).trim();
85+
86+
} catch (error) {
87+
console.error('Command execution error:', error);
88+
throw new Error(`Failed to execute command: ${error}`);
89+
}
7890
}
7991
}
8092

0 commit comments

Comments
 (0)