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:
17
ui.py
17
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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user