From 3babef42768a63fb097218a0c7ea52085b41beb8 Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Thu, 25 Jun 2026 15:51:38 +0700 Subject: [PATCH] Fixing prompt cancelation --- interfaces/tui/app.py | 8 +++++++- interfaces/tui/input.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interfaces/tui/app.py b/interfaces/tui/app.py index a3ecafc..32cae91 100644 --- a/interfaces/tui/app.py +++ b/interfaces/tui/app.py @@ -111,6 +111,7 @@ class HendrikTUI: curses.use_default_colors() init_colors() stdscr.keypad(True) + curses.raw() # Ctrl+C sebagai key code 3, bukan SIGINT → KeyboardInterrupt stdscr.refresh() self.messages = [{"role": "system", "content": self.build_system_prompt( @@ -140,7 +141,12 @@ class HendrikTUI: try: key = stdscr.getch() except KeyboardInterrupt: - break + if self.processing: + self.llm.cancel_requested = True + self.agent_done.set() + else: + break + key = -1 handle_key(self, stdscr, key) diff --git a/interfaces/tui/input.py b/interfaces/tui/input.py index 74ab010..0b0789c 100644 --- a/interfaces/tui/input.py +++ b/interfaces/tui/input.py @@ -39,9 +39,9 @@ def handle_key(app, stdscr, key): processing = app.processing # -- Always allowed (even during processing) -- - if key == 3: # Ctrl+C → cancel stream jika processing, exit jika tidak + # Check for Ctrl+C (key 3) and also potential curses representation of Ctrl+C + if key == 3 or key == 26: # 3 is Ctrl+C, 26 is Ctrl+Z (sometimes mapped) if processing: - # Cancel stream yang sedang berjalan app.llm.cancel_requested = True log(app, "system", " Stream cancelled by user") else: