@@ -5,6 +5,53 @@ import * as os from "os";
55let mainWindow : BrowserWindow ;
66const terminals = new Map < string , pty . IPty > ( ) ;
77
8+ // Create new terminal
9+ ipcMain . on ( "create-terminal" , ( event ) => {
10+ const terminalId = `terminal-${ Date . now ( ) } ` ;
11+ const shell = os . platform ( ) === "darwin" ? "zsh" : "bash" ;
12+
13+ const ptyProcess = pty . spawn ( shell , [ ] , {
14+ name : "xterm-color" ,
15+ cols : 80 ,
16+ rows : 30 ,
17+ cwd : process . env . HOME ,
18+ env : process . env ,
19+ } ) ;
20+
21+ terminals . set ( terminalId , ptyProcess ) ;
22+
23+ ptyProcess . onData ( ( data ) => {
24+ mainWindow . webContents . send ( "terminal-output" , terminalId , data ) ;
25+ } ) ;
26+
27+ event . reply ( "terminal-created" , terminalId ) ;
28+ } ) ;
29+
30+ // Handle terminal input
31+ ipcMain . on ( "terminal-input" , ( _event , terminalId : string , data : string ) => {
32+ const terminal = terminals . get ( terminalId ) ;
33+ if ( terminal ) {
34+ terminal . write ( data ) ;
35+ }
36+ } ) ;
37+
38+ // Handle terminal resize
39+ ipcMain . on ( "terminal-resize" , ( _event , terminalId : string , cols : number , rows : number ) => {
40+ const terminal = terminals . get ( terminalId ) ;
41+ if ( terminal ) {
42+ terminal . resize ( cols , rows ) ;
43+ }
44+ } ) ;
45+
46+ // Handle terminal close
47+ ipcMain . on ( "close-terminal" , ( _event , terminalId : string ) => {
48+ const terminal = terminals . get ( terminalId ) ;
49+ if ( terminal ) {
50+ terminal . kill ( ) ;
51+ terminals . delete ( terminalId ) ;
52+ }
53+ } ) ;
54+
855const createWindow = ( ) => {
956 mainWindow = new BrowserWindow ( {
1057 width : 1400 ,
@@ -16,53 +63,6 @@ const createWindow = () => {
1663 } ) ;
1764
1865 mainWindow . loadFile ( "index.html" ) ;
19-
20- // Create new terminal
21- ipcMain . on ( "create-terminal" , ( event ) => {
22- const terminalId = `terminal-${ Date . now ( ) } ` ;
23- const shell = os . platform ( ) === "darwin" ? "zsh" : "bash" ;
24-
25- const ptyProcess = pty . spawn ( shell , [ ] , {
26- name : "xterm-color" ,
27- cols : 80 ,
28- rows : 30 ,
29- cwd : process . env . HOME ,
30- env : process . env ,
31- } ) ;
32-
33- terminals . set ( terminalId , ptyProcess ) ;
34-
35- ptyProcess . onData ( ( data ) => {
36- mainWindow . webContents . send ( "terminal-output" , terminalId , data ) ;
37- } ) ;
38-
39- event . reply ( "terminal-created" , terminalId ) ;
40- } ) ;
41-
42- // Handle terminal input
43- ipcMain . on ( "terminal-input" , ( _event , terminalId : string , data : string ) => {
44- const terminal = terminals . get ( terminalId ) ;
45- if ( terminal ) {
46- terminal . write ( data ) ;
47- }
48- } ) ;
49-
50- // Handle terminal resize
51- ipcMain . on ( "terminal-resize" , ( _event , terminalId : string , cols : number , rows : number ) => {
52- const terminal = terminals . get ( terminalId ) ;
53- if ( terminal ) {
54- terminal . resize ( cols , rows ) ;
55- }
56- } ) ;
57-
58- // Handle terminal close
59- ipcMain . on ( "close-terminal" , ( _event , terminalId : string ) => {
60- const terminal = terminals . get ( terminalId ) ;
61- if ( terminal ) {
62- terminal . kill ( ) ;
63- terminals . delete ( terminalId ) ;
64- }
65- } ) ;
6666} ;
6767
6868app . whenReady ( ) . then ( ( ) => {
0 commit comments