diff --git a/ui.py b/ui.py index cb74674..981d330 100644 --- a/ui.py +++ b/ui.py @@ -230,6 +230,10 @@ class UIManager: """Create all UI windows""" maxy, maxx = self.screen.getmaxyx() + # Minimum terminal size check + if maxy < 20 or maxx < 80: + return False + # Server info window (top) self.info_window = curses.newwin( INFO_WINDOW_HEIGHT, @@ -285,6 +289,53 @@ class UIManager: self.screen.noutrefresh() curses.doupdate() + return True + + def handle_resize(self): + """Handle terminal resize event""" + try: + # Get new terminal dimensions + maxy, maxx = self.screen.getmaxyx() + + # Minimum size check + if maxy < 20 or maxx < 80: + return False + + # Update screen + curses.update_lines_cols() + self.screen.clear() + self.screen.addstr(0, 0, f"Quake Live PyCon: {self.host}") + self.screen.noutrefresh() + + # Recreate windows with new dimensions + self.info_window.resize(INFO_WINDOW_HEIGHT, maxx - 4) + self.info_window.mvwin(INFO_WINDOW_Y, 2) + + self.output_window.resize(maxy - 17, maxx - 4) + self.output_window.mvwin(OUTPUT_WINDOW_Y, 2) + + self.divider_window.resize(1, maxx - 4) + self.divider_window.mvwin(maxy - 3, 2) + self.divider_window.clear() + self.divider_window.hline(curses.ACS_HLINE, maxx - 4) + + self.input_window.resize(INPUT_WINDOW_HEIGHT, maxx - 6) + self.input_window.mvwin(maxy - 2, 4) + + self.screen.addstr(maxy - 2, 2, '$ ') + + # Refresh all windows + self.info_window.noutrefresh() + self.output_window.noutrefresh() + self.divider_window.noutrefresh() + self.input_window.noutrefresh() + self.screen.noutrefresh() + curses.doupdate() + + return True + + except curses.error: + return False def setup_input_queue(self): """Setup threaded input queue with command history and autocomplete""" @@ -308,6 +359,17 @@ class UIManager: if key == -1: # No input continue + # Handle terminal resize + if key == curses.KEY_RESIZE: + manager.handle_resize() + # Redraw input + window.erase() + window.addstr(0, 0, current_input) + window.move(0, cursor_pos) + window.noutrefresh() + curses.doupdate() + continue + # Tab key - cycle through suggestions if key == ord('\t') or key == 9: if suggestions: