Skip to content

Commit 7fd4968

Browse files
committed
some terminal session fixes
1 parent 272f763 commit 7fd4968

File tree

2 files changed

+47
-52
lines changed

2 files changed

+47
-52
lines changed

main.ts

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,53 @@ import * as os from "os";
55
let mainWindow: BrowserWindow;
66
const 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+
855
const 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

6868
app.whenReady().then(() => {

renderer.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,3 @@ ipcRenderer.on("terminal-created", (_event, terminalId: string) => {
198198
document.getElementById("new-terminal")?.addEventListener("click", () => {
199199
ipcRenderer.send("create-terminal");
200200
});
201-
202-
// Create first terminal on load
203-
window.addEventListener("DOMContentLoaded", () => {
204-
ipcRenderer.send("create-terminal");
205-
});

0 commit comments

Comments
 (0)