fix(tui): prevent cursor crash and status bar text bleed

This commit is contained in:
Dita Aji Pratama 2026-05-26 13:48:59 +07:00
parent 315cd77639
commit 25c6fa3bdb
2 changed files with 8 additions and 6 deletions

View File

@ -35,7 +35,6 @@ class HendrikTUI:
curses.wrapper(self._main) curses.wrapper(self._main)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
print("Exiting.")
def _main(self, stdscr): def _main(self, stdscr):
# Main loop: draw → getch → handle # Main loop: draw → getch → handle

View File

@ -230,8 +230,8 @@ def draw_input(app, stdscr):
except curses.error: except curses.error:
pass pass
# Cursor position # Cursor position — only on the visual chunk that contains the cursor
if line_is_active and not app.processing: if idx == cur_visual and not app.processing:
col_on_visual = app.input_col - start col_on_visual = app.input_col - start
cursor_yx = (y, 4 + min(col_on_visual, len(chunk))) cursor_yx = (y, 4 + min(col_on_visual, len(chunk)))
@ -248,7 +248,10 @@ def draw_input(app, stdscr):
pass pass
if cursor_yx: if cursor_yx:
stdscr.move(*cursor_yx) try:
stdscr.move(*cursor_yx)
except curses.error:
pass
def draw_status(app, stdscr): def draw_status(app, stdscr):
@ -262,8 +265,8 @@ def draw_status(app, stdscr):
if len(ws) > max_ws: if len(ws) > max_ws:
ws = ".." + ws[-(max_ws - 2):] ws = ".." + ws[-(max_ws - 2):]
status = f" {ws} \u2502{mode}\u2502{hints}" status = (f" {ws} \u2502{mode}\u2502{hints}").ljust(w)[:w]
stdscr.addstr(y, 0, status[:w], curses.color_pair(C_STATUS_INFO)) stdscr.addstr(y, 0, status, curses.color_pair(C_STATUS_INFO))
# Highlight mode dengan warna berbeda # Highlight mode dengan warna berbeda
mode_start = len(f" {ws} \u2502") mode_start = len(f" {ws} \u2502")