Fixing prompt cancelation

This commit is contained in:
Dita Aji Pratama 2026-06-25 15:51:38 +07:00
parent 4f4e686ca1
commit 3babef4276
2 changed files with 9 additions and 3 deletions

View File

@ -111,6 +111,7 @@ class HendrikTUI:
curses.use_default_colors() curses.use_default_colors()
init_colors() init_colors()
stdscr.keypad(True) stdscr.keypad(True)
curses.raw() # Ctrl+C sebagai key code 3, bukan SIGINT → KeyboardInterrupt
stdscr.refresh() stdscr.refresh()
self.messages = [{"role": "system", "content": self.build_system_prompt( self.messages = [{"role": "system", "content": self.build_system_prompt(
@ -140,7 +141,12 @@ class HendrikTUI:
try: try:
key = stdscr.getch() key = stdscr.getch()
except KeyboardInterrupt: except KeyboardInterrupt:
break if self.processing:
self.llm.cancel_requested = True
self.agent_done.set()
else:
break
key = -1
handle_key(self, stdscr, key) handle_key(self, stdscr, key)

View File

@ -39,9 +39,9 @@ def handle_key(app, stdscr, key):
processing = app.processing processing = app.processing
# -- Always allowed (even during 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: if processing:
# Cancel stream yang sedang berjalan
app.llm.cancel_requested = True app.llm.cancel_requested = True
log(app, "system", " Stream cancelled by user") log(app, "system", " Stream cancelled by user")
else: else: