@@ -4,74 +4,77 @@ import { promisify } from 'node:util';
4
4
const execPromise = promisify ( exec ) ;
5
5
6
6
class CommandExecutor {
7
- async executeCommand ( command : string ) : Promise < string > {
7
+ async isProcessing ( ) : Promise < boolean > {
8
8
const ascript = `
9
9
tell application "iTerm2"
10
10
activate
11
- delay 0.1
12
-
13
11
if windows is equal to {} then
14
12
create window with default profile
15
- delay 0.1
16
13
end if
17
14
18
15
tell front window
19
16
if current session of current tab is missing value then
20
17
create tab with default profile
21
- delay 0.1
22
18
end if
23
19
24
20
tell current session of current tab
25
- write text " ${ command . replace ( / " / g , '\\"' ) } "
21
+ return is processing
26
22
end tell
27
23
end tell
28
24
end tell
29
25
` ;
30
-
31
- const { stdout } = await execPromise ( `osascript -e '${ ascript } '` ) ;
32
- return stdout ;
26
+
27
+ try {
28
+ const { stdout } = await execPromise ( `osascript -e '${ ascript } '` ) ;
29
+ return stdout . trim ( ) === 'true' ;
30
+ } catch ( error ) {
31
+ throw new Error ( `Failed to check processing status: ${ error } ` ) ;
32
+ }
33
33
}
34
34
35
- async createNewTab ( ) : Promise < void > {
35
+ async executeCommand ( command : string ) : Promise < string > {
36
36
const ascript = `
37
37
tell application "iTerm2"
38
38
activate
39
- delay 0.1
40
-
41
39
if windows is equal to {} then
42
40
create window with default profile
43
- else
44
- tell front window
41
+ end if
42
+
43
+ tell front window
44
+ if current session of current tab is missing value then
45
45
create tab with default profile
46
+ end if
47
+
48
+ tell current session of current tab
49
+ write text "${ command . replace ( / " / g, '\\"' ) } "
46
50
end tell
47
- end if
51
+ end tell
48
52
end tell
49
53
` ;
50
-
51
- await execPromise ( `osascript -e '${ ascript } '` ) ;
52
- }
53
54
54
- async splitPane ( vertical : boolean = true ) : Promise < void > {
55
- const direction = vertical ? "vertical" : "horizontal" ;
56
- const ascript = `
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 = `
57
64
tell application "iTerm2"
58
- activate
59
- delay 0.1
60
-
61
- if windows is equal to {} then
62
- create window with default profile
63
- delay 0.1
64
- end if
65
-
66
65
tell front window
67
66
tell current session of current tab
68
- split ${ direction } ly with default profile
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
69
71
end tell
70
72
end tell
71
73
end tell
72
74
` ;
73
75
74
- await execPromise ( `osascript -e '${ ascript } '` ) ;
76
+ const { stdout } = await execPromise ( `osascript -e '${ getOutput } '` ) ;
77
+ return stdout ;
75
78
}
76
79
}
77
80
0 commit comments