@@ -8,6 +8,7 @@ import {
88 loadImageFile,
99 } from "./image-types.ts";
1010 import { loadSkills } from "./skills.ts";
11+import { terminal } from "./terminal-io.ts";
1112
1213 // ─── ANSI escape sequences ────────────────────────────────────────────────────
1314
@@ -195,12 +196,16 @@ export function watchForInterrupt(
195196 ): () => void {
196197 if (!process.stdin.isTTY) return () => {};
197198
199+ const onInterrupt = () => {
200+ cleanup();
201+ abortController.abort();
202+ };
203+
198204 const onData = (chunk: Buffer) => {
199205 for (const byte of chunk) {
200206 if (byte === 0x03) {
201207 // Ctrl+C received — abort and clean up immediately.
202- cleanup();
203- abortController.abort();
208+ onInterrupt();
204209 return;
205210 }
206211 }
@@ -208,10 +213,12 @@ export function watchForInterrupt(
208213
209214 const cleanup = () => {
210215 process.stdin.removeListener("data", onData);
216+ terminal.setInterruptHandler(null);
211217 process.stdin.setRawMode(false);
212218 process.stdin.pause();
213219 };
214220
221+ terminal.setInterruptHandler(onInterrupt);
215222 process.stdin.setRawMode(true);
216223 process.stdin.resume();
217224 process.stdin.on("data", onData);