This commit is contained in:
xbl
2025-12-29 08:05:47 +01:00
parent 3f61ff1a06
commit 18cf31073f

61
ui.py
View File

@ -96,10 +96,11 @@ class UIManager:
curses.start_color()
curses.use_default_colors()
curses.cbreak()
curses.setsyx(-1, -1)
curses.curs_set(0)
#curses.setsyx(-1, -1)
self.screen.addstr(f"Quake Live PyCon: {self.host}")
self.screen.refresh()
self.screen.noutrefresh()
# Initialize color pairs
for i in range(1, 7):
@ -123,7 +124,7 @@ class UIManager:
self.info_window.scrollok(False)
self.info_window.idlok(False)
self.info_window.leaveok(True)
self.info_window.refresh()
self.info_window.noutrefresh()
# Output window (middle - main display)
self.output_window = curses.newwin(
@ -133,9 +134,23 @@ class UIManager:
2
)
self.output_window.scrollok(True)
self.output_window.idlok(True)
self.output_window.idlok(False)
self.output_window.idcok(False)
self.output_window.leaveok(True)
self.output_window.refresh()
self.output_window.noutrefresh()
# Divider line
self.divider_window = curses.newwin(
1,
maxx - 4,
maxy - 3,
2
)
self.divider_window.hline(curses.ACS_HLINE, maxx - 4)
self.divider_window.scrollok(False)
self.divider_window.idlok(False)
self.divider_window.leaveok(True)
self.divider_window.noutrefresh()
# Input window (bottom)
self.input_window = curses.newwin(
@ -148,20 +163,12 @@ class UIManager:
self.input_window.nodelay(False)
self.screen.addstr(maxy - 2, 2, '$ ')
self.input_window.idlok(True)
self.input_window.idcok(True)
self.input_window.leaveok(False)
self.input_window.refresh()
self.input_window.noutrefresh()
# Divider line
self.divider_window = curses.newwin(
1,
maxx - 4,
maxy - 3,
2
)
self.divider_window.hline(curses.ACS_HLINE, maxx - 4)
self.divider_window.refresh()
self.screen.refresh()
self.screen.noutrefresh()
curses.doupdate()
def setup_input_queue(self):
"""Setup threaded input queue with command history"""
@ -192,7 +199,7 @@ class UIManager:
cursor_pos = 0
temp_history_index = -1
temp_input = ""
window.clear()
window.erase()
window.noutrefresh()
# Arrow UP - previous command
@ -207,7 +214,7 @@ class UIManager:
temp_history_index -= 1
current_input = manager.command_history[temp_history_index]
cursor_pos = len(current_input)
window.clear()
window.erase()
window.addstr(0, 0, current_input)
window.noutrefresh()
@ -224,7 +231,7 @@ class UIManager:
current_input = manager.command_history[temp_history_index]
cursor_pos = len(current_input)
window.clear()
window.erase()
window.addstr(0, 0, current_input)
window.noutrefresh()
@ -248,7 +255,7 @@ class UIManager:
current_input = current_input[:cursor_pos-1] + current_input[cursor_pos:]
cursor_pos -= 1
temp_history_index = -1 # Exit history mode
window.clear()
window.erase()
window.addstr(0, 0, current_input)
window.move(0, cursor_pos)
window.noutrefresh()
@ -259,17 +266,18 @@ class UIManager:
current_input = current_input[:cursor_pos] + char + current_input[cursor_pos:]
cursor_pos += 1
temp_history_index = -1 # Exit history mode
window.clear()
window.erase()
window.addstr(0, 0, current_input)
window.move(0, cursor_pos)
window.noutrefresh()
curses.doupdate()
except Exception as e:
import logging
logging.getLogger('ui').error(f'Input error: {e}')
window.move(0, cursor_pos)
curses.doupdate()
self.input_queue = queue.Queue()
t = threading.Thread(target=wait_stdin, args=(self.input_queue, self.input_window, self))
t.daemon = True
@ -286,15 +294,14 @@ class UIManager:
def print_message(self, message, attributes=0):
"""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)
self.input_window.move(0, 0)
curses.doupdate()
def update_server_info(self, game_state):
"""Update server info window"""
self.info_window.clear()
self.info_window.erase()
max_y, max_x = self.info_window.getmaxyx()
server_info = game_state.server_info