From 530c12d9c025056ab68605fc797a5c9b712d6960 Mon Sep 17 00:00:00 2001 From: pfl Date: Fri, 9 Jan 2026 15:13:52 +0100 Subject: [PATCH] Fix curses error in print_colored at window boundaries - Wrap all addch calls in try/except blocks - Return early when hitting window boundary - Prevents crash when content exceeds window dimensions - Gracefully truncates output instead of throwing error --- ui.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ui.py b/ui.py index e66199c..d9f82f5 100644 --- a/ui.py +++ b/ui.py @@ -46,7 +46,10 @@ def print_colored(window, message, attributes=0): ^0 = reset, ^1 = red, ^2 = green, ^3 = yellow, ^4 = blue, ^5 = cyan, ^6 = magenta, ^7 = white, ^8 = bold, ^9 = underline """ if not curses.has_colors: - window.addstr(message) + try: + window.addstr(message) + except curses.error: + pass return color = 0 @@ -69,13 +72,19 @@ def print_colored(window, message, attributes=0): elif ord('1') <= val <= ord('6'): color = val - ord('0') else: - window.addch('^', curses.color_pair(color) | (curses.A_BOLD if bold else 0) | (curses.A_UNDERLINE if underline else 0) | attributes) - window.addch(ch, curses.color_pair(color) | (curses.A_BOLD if bold else 0) | (curses.A_UNDERLINE if underline else 0) | attributes) + try: + window.addch('^', curses.color_pair(color) | (curses.A_BOLD if bold else 0) | (curses.A_UNDERLINE if underline else 0) | attributes) + window.addch(ch, curses.color_pair(color) | (curses.A_BOLD if bold else 0) | (curses.A_UNDERLINE if underline else 0) | attributes) + except curses.error: + return parse_color = False elif ch == '^': parse_color = True else: - window.addch(ch, curses.color_pair(color) | (curses.A_BOLD if bold else 0) | (curses.A_UNDERLINE if underline else 0) | attributes) + try: + window.addch(ch, curses.color_pair(color) | (curses.A_BOLD if bold else 0) | (curses.A_UNDERLINE if underline else 0) | attributes) + except curses.error: + return def update_autocomplete_display(window, current_input, first_word, words, ends_with_space): """