Pass stdscr to _submit for realtime screen updates during processing

This commit is contained in:
Dita Aji Pratama 2026-05-12 16:28:07 +07:00
parent 293bd5d550
commit d4ec96ff62

View File

@ -228,7 +228,7 @@ class HendrikTUI:
def _handle_key(self, stdscr, key):
if key == 4:
self._submit()
self._submit(stdscr)
elif key == 23:
self._workspace_popup(stdscr)
elif key == 3:
@ -308,7 +308,7 @@ class HendrikTUI:
"time": datetime.now().strftime("%H:%M"),
})
def _submit(self):
def _submit(self, stdscr):
query = "\n".join(self.input_buffer).strip()
if not query:
return
@ -319,12 +319,16 @@ class HendrikTUI:
self.input_col = 0
self.scroll = 999999
self.processing = True
self._draw(stdscr)
stdscr.refresh()
self.messages.append({"role": "user", "content": query})
for step in range(self.agent_max_iterations):
self._log("system", f" step {step + 1} \u2014 LLM...")
self.scroll = 999999
self._draw(stdscr)
stdscr.refresh()
response = self.llm.chat(self.messages, tools=self.TOOLS)
@ -340,13 +344,17 @@ class HendrikTUI:
if response.content and response.content.strip():
self._log("ai", response.content)
self.scroll = 999999
self._draw(stdscr)
stdscr.refresh()
for tc in response.tool_calls:
tname = tc["function"]["name"]
targs = tc["function"]["arguments"]
self._log("system", f" \u2192 {tname}")
self.scroll = 999999
self._draw(stdscr)
stdscr.refresh()
self._execute_tool(tc)
else:
if response.content:
self.messages.append({
"role": "assistant",
"content": response.content,
@ -355,6 +363,8 @@ class HendrikTUI:
self._log("sep", "")
self.processing = False
self.scroll = 999999
self._draw(stdscr)
stdscr.refresh()
return
self._log("error", "Max iterations reached without final answer.")