This commit is contained in:
xbl
2025-12-24 10:02:04 +01:00
parent 53c0b3af55
commit 3f61ff1a06

35
ui.py
View File

@ -27,10 +27,12 @@ class CursesHandler(logging.Handler):
fs = "%s\n"
try:
print_colored(self.window, fs % msg, 0)
self.window.refresh()
self.window.noutrefresh()
curses.doupdate()
except UnicodeError:
print_colored(self.window, fs % msg.encode("UTF-8"), 0)
self.window.refresh()
self.window.noutrefresh()
curses.doupdate()
except (KeyboardInterrupt, SystemExit):
raise
except:
@ -69,8 +71,6 @@ def print_colored(window, message, attributes=0):
else:
window.addch(ch, curses.color_pair(color) | (curses.A_BOLD if bold else 0) | attributes)
window.refresh()
class UIManager:
"""Manages curses windows and display"""
@ -193,7 +193,7 @@ class UIManager:
temp_history_index = -1
temp_input = ""
window.clear()
window.refresh()
window.noutrefresh()
# Arrow UP - previous command
elif key == curses.KEY_UP:
@ -209,7 +209,7 @@ class UIManager:
cursor_pos = len(current_input)
window.clear()
window.addstr(0, 0, current_input)
window.refresh()
window.noutrefresh()
# Arrow DOWN - next command
elif key == curses.KEY_DOWN:
@ -226,29 +226,21 @@ class UIManager:
cursor_pos = len(current_input)
window.clear()
window.addstr(0, 0, current_input)
window.refresh()
window.noutrefresh()
# Arrow LEFT - move cursor left
elif key == curses.KEY_LEFT:
if cursor_pos > 0:
cursor_pos -= 1
window.move(0, cursor_pos)
window.refresh()
window.noutrefresh()
# Arrow RIGHT - move cursor right
elif key == curses.KEY_RIGHT:
if cursor_pos < len(current_input):
cursor_pos += 1
window.move(0, cursor_pos)
window.refresh()
# ESC - cancel quit confirmation
elif key == 27:
if quit_confirm:
quit_confirm = False
window.clear()
window.refresh()
window.noutrefresh()
# Backspace
elif key in (curses.KEY_BACKSPACE, 127, 8):
@ -259,7 +251,7 @@ class UIManager:
window.clear()
window.addstr(0, 0, current_input)
window.move(0, cursor_pos)
window.refresh()
window.noutrefresh()
# Regular character
elif 32 <= key <= 126:
@ -270,7 +262,9 @@ class UIManager:
window.clear()
window.addstr(0, 0, current_input)
window.move(0, cursor_pos)
window.refresh()
window.noutrefresh()
curses.doupdate()
except Exception as e:
import logging
@ -294,6 +288,7 @@ class UIManager:
"""Print formatted message to output window"""
y, x = curses.getsyx()
print_colored(self.output_window, message, attributes)
self.output_window.noutrefresh()
curses.setsyx(y, x)
curses.doupdate()
@ -367,4 +362,4 @@ class UIManager:
separator = "^7" + "" * (max_x - 1) + "^7"
print_colored(self.info_window, separator, 0)
self.info_window.refresh()
self.info_window.noutrefresh()