Try out suspension
This commit is contained in:
parent
9586925234
commit
fd9ec777a3
1 changed files with 22 additions and 0 deletions
22
src/cli.ts
22
src/cli.ts
|
|
@ -140,6 +140,20 @@ async function main() {
|
||||||
|
|
||||||
process.on("SIGINT", cleanup);
|
process.on("SIGINT", cleanup);
|
||||||
process.on("SIGTERM", cleanup);
|
process.on("SIGTERM", cleanup);
|
||||||
|
process.on("SIGCONT", () => {
|
||||||
|
// Restore terminal state after being resumed from suspension
|
||||||
|
if (process.stdin.isTTY) {
|
||||||
|
process.stdin.setRawMode(true);
|
||||||
|
}
|
||||||
|
process.stdin.resume();
|
||||||
|
if (pty) {
|
||||||
|
// Resume child process
|
||||||
|
process.kill(pty.pid, "SIGCONT");
|
||||||
|
// Trigger PTY redraw by sending resize
|
||||||
|
const { cols, rows } = getTerminalSize();
|
||||||
|
pty.resize(cols, rows);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Spawn PTY only after WebSocket connects
|
// Spawn PTY only after WebSocket connects
|
||||||
const spawnClaude = () => {
|
const spawnClaude = () => {
|
||||||
|
|
@ -160,6 +174,14 @@ async function main() {
|
||||||
|
|
||||||
// Forward local stdin to PTY
|
// Forward local stdin to PTY
|
||||||
process.stdin.on("data", (data: Buffer) => {
|
process.stdin.on("data", (data: Buffer) => {
|
||||||
|
// ctrl+z in raw mode - suspend child and self
|
||||||
|
if (data.length === 1 && data[0] === 0x1a) {
|
||||||
|
if (pty) {
|
||||||
|
process.kill(pty.pid, "SIGTSTP");
|
||||||
|
}
|
||||||
|
process.kill(process.pid, "SIGTSTP");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (pty) {
|
if (pty) {
|
||||||
pty.write(data.toString());
|
pty.write(data.toString());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue