From 25c6fa3bdba5fc810fdd85f44c10f4a0402a4ba7 Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Tue, 26 May 2026 13:48:59 +0700 Subject: [PATCH] fix(tui): prevent cursor crash and status bar text bleed --- tui/app.py | 1 - tui/render.py | 13 ++++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tui/app.py b/tui/app.py index bff4e12..eec1d80 100644 --- a/tui/app.py +++ b/tui/app.py @@ -35,7 +35,6 @@ class HendrikTUI: curses.wrapper(self._main) except KeyboardInterrupt: pass - print("Exiting.") def _main(self, stdscr): # Main loop: draw → getch → handle diff --git a/tui/render.py b/tui/render.py index c14458e..b073343 100644 --- a/tui/render.py +++ b/tui/render.py @@ -230,8 +230,8 @@ def draw_input(app, stdscr): except curses.error: pass - # Cursor position - if line_is_active and not app.processing: + # Cursor position — only on the visual chunk that contains the cursor + if idx == cur_visual and not app.processing: col_on_visual = app.input_col - start cursor_yx = (y, 4 + min(col_on_visual, len(chunk))) @@ -248,7 +248,10 @@ def draw_input(app, stdscr): pass if cursor_yx: - stdscr.move(*cursor_yx) + try: + stdscr.move(*cursor_yx) + except curses.error: + pass def draw_status(app, stdscr): @@ -262,8 +265,8 @@ def draw_status(app, stdscr): if len(ws) > max_ws: ws = ".." + ws[-(max_ws - 2):] - status = f" {ws} \u2502{mode}\u2502{hints}" - stdscr.addstr(y, 0, status[:w], curses.color_pair(C_STATUS_INFO)) + status = (f" {ws} \u2502{mode}\u2502{hints}").ljust(w)[:w] + stdscr.addstr(y, 0, status, curses.color_pair(C_STATUS_INFO)) # Highlight mode dengan warna berbeda mode_start = len(f" {ws} \u2502")