diff --git a/ui/curses_ui.py b/ui/curses_ui.py index 1464fba..1ee86d6 100644 --- a/ui/curses_ui.py +++ b/ui/curses_ui.py @@ -11,8 +11,6 @@ import default_config as config import ui.dialog import globals - - def handle_resize(stdscr, firstrun): global messages_pad, messages_win, nodes_pad, nodes_win, channel_pad, channel_win, function_win, packetlog_win, entry_win @@ -37,31 +35,46 @@ def handle_resize(stdscr, firstrun): nodes_pad = curses.newpad(1,1) channel_pad = curses.newpad(1,1) - entry_win.bkgd(get_color("background")) - channel_win.bkgd(get_color("background")) - messages_win.bkgd(get_color("background")) - nodes_win.bkgd(get_color("background")) - function_win.bkgd(get_color("background")) - packetlog_win.bkgd(get_color("background")) + # Set background colors for windows + for win in [entry_win, channel_win, messages_win, nodes_win, function_win, packetlog_win]: + win.bkgd(get_color("background")) - messages_pad.bkgd(get_color("background")) - nodes_pad.bkgd(get_color("background")) - channel_pad.bkgd(get_color("background")) + # Set background colors for pads + for pad in [messages_pad, nodes_pad, channel_pad]: + pad.bkgd(get_color("background")) + # Set colors for window frames + for win in [channel_win, entry_win, nodes_win, messages_win, function_win]: + win.attrset(get_color("window_frame")) - channel_win.attrset(get_color("window_frame")) - entry_win.attrset(get_color("window_frame")) - nodes_win.attrset(get_color("window_frame")) - messages_win.attrset(get_color("window_frame")) - function_win.attrset(get_color("window_frame")) else: - entry_win.erase() - channel_win.erase() - messages_win.erase() - nodes_win.erase() - function_win.erase() - packetlog_win.erase() + # Ensure all windows are initialized before using them + if entry_win is None: + entry_win = curses.newwin(3, width, 0, 0) + if channel_win is None: + channel_win = curses.newwin(height - 6, channel_width, 3, 0) + if messages_win is None: + messages_win = curses.newwin(height - 6, messages_width, 3, channel_width) + if nodes_win is None: + nodes_win = curses.newwin(height - 6, nodes_width, 3, channel_width + messages_width) + if function_win is None: + function_win = curses.newwin(3, width, height - 3, 0) + if packetlog_win is None: + packetlog_win = curses.newwin(int(height / 3), messages_width, height - int(height / 3) - 3, channel_width) + + # Ensure pads are initialized + if messages_pad is None: + messages_pad = curses.newpad(1,1) + if nodes_pad is None: + nodes_pad = curses.newpad(1,1) + if channel_pad is None: + channel_pad = curses.newpad(1,1) + + + for win in [entry_win, channel_win, messages_win, nodes_win, function_win, packetlog_win]: + win.erase() + entry_win.resize(3, width) channel_win.resize(height - 6, channel_width) messages_win.resize(height - 6, messages_width) @@ -73,27 +86,12 @@ def handle_resize(stdscr, firstrun): packetlog_win.resize(int(height / 3), messages_width) packetlog_win.mvwin(height - int(height / 3) - 3, channel_width) - # Reinitialize `nodes_pad` in case it was lost during a resize. - # We shouldn't need this but nodes_pad keeps throwing and error in draw_node_list so... - try: - nodes_pad.getmaxyx() # Check if it's still valid - except: - nodes_pad = curses.newpad(1, 1) # Recreate if needed + # Draw window borders + for win in [channel_win, entry_win, nodes_win, messages_win, function_win]: + win.box() + win.refresh() - channel_win.box() - entry_win.box() - nodes_win.box() - messages_win.box() - - function_win.box() - - # Refresh all windows - entry_win.refresh() - channel_win.refresh() - function_win.refresh() - nodes_win.refresh() - messages_win.refresh() entry_win.keypad(True) curses.curs_set(1) @@ -435,6 +433,10 @@ def draw_messages_window(scroll_to_bottom = False): draw_packetlog_win() def draw_node_list(): + # global nodes_pad + # if nodes_pad is None: + # nodes_pad = curses.newpad(1, 1) + try: nodes_pad.erase() box_width = nodes_win.getmaxyx()[1]