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
This commit is contained in:
pfl
2026-01-09 15:13:52 +01:00
parent 993ed4f051
commit 530c12d9c0

9
ui.py
View File

@ -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:
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:
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:
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):
"""