From 35748d071e85c1a93852f04f67604b89efdf1bd7 Mon Sep 17 00:00:00 2001 From: Russell Schmidt Date: Sun, 19 Jan 2025 14:52:11 -0600 Subject: [PATCH] Various tweaks, added back messages border --- ui/curses_ui.py | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/ui/curses_ui.py b/ui/curses_ui.py index c311800..1ed22a2 100644 --- a/ui/curses_ui.py +++ b/ui/curses_ui.py @@ -87,33 +87,22 @@ def draw_channel_list(): def draw_messages_window(): """Update the messages window based on the selected channel and scroll position.""" - messages_win.clear() + messages_pad.clear() channel = globals.channel_list[globals.selected_channel] if channel in globals.all_messages: messages = globals.all_messages[channel] - num_messages = len(messages) - max_messages = messages_win.getmaxyx()[0] - 2 # Max messages that fit in the window # Adjust for packetlog height if log is visible if globals.display_log: packetlog_height = packetlog_win.getmaxyx()[0] - max_messages -= packetlog_height - 1 - if max_messages < 1: - max_messages = 1 - - # Calculate the scroll position based on the current selection - # max_scroll_position = max(0, num_messages - max_messages) - # start_index = max(0, min(globals.selected_message, max_scroll_position)) # Display messages starting from the calculated start index - # row = 1 row = 0 for (prefix, message) in messages: full_message = f"{prefix}{message}" - wrapped_lines = textwrap.wrap(full_message, messages_width - 2) - + wrapped_lines = textwrap.wrap(full_message, messages_box.getmaxyx()[1] - 2) for line in wrapped_lines: # Highlight the row if it's the selected message @@ -121,11 +110,12 @@ def draw_messages_window(): # color = curses.color_pair(3) # Highlighted row color # else: color = curses.color_pair(1) if prefix.startswith(globals.sent_message_prefix) else curses.color_pair(2) - messages_win.addstr(row, 1, line, color) + messages_pad.addstr(row, 1, line, color) row += 1 - # messages_win.box() - messages_win.refresh(0, 0, 3, channel_width, 3 + height - 6, channel_width + messages_width - 1) + messages_pad.refresh(0, 0, + messages_box.getbegyx()[0] + 1, messages_box.getbegyx()[1] + 1, + messages_box.getbegyx()[0] + messages_box.getmaxyx()[0] - 2, messages_box.getbegyx()[1] + messages_box.getmaxyx()[1] - 2) draw_packetlog_win() @@ -172,7 +162,12 @@ def select_messages(direction): # draw_messages_window() - messages_win.refresh(globals.selected_message, 0, 3, channel_width, 3 + height - 6, channel_width + messages_width - 1) + # messages_win.refresh(globals.selected_message, 0, 4, channel_width + 1, 3 + height - 8, channel_width + messages_width - 2) + messages_pad.refresh(globals.selected_message, 0, + messages_box.getbegyx()[0] + 1, messages_box.getbegyx()[1] + 1, + messages_box.getbegyx()[0] + messages_box.getmaxyx()[0] - 2, messages_box.getbegyx()[1] + messages_box.getmaxyx()[1] - 2) + + def select_nodes(direction): node_list_length = len(globals.node_list) @@ -231,7 +226,7 @@ def draw_packetlog_win(): def main_ui(stdscr): - global messages_win, nodes_win, channel_win, function_win, packetlog_win, channel_width, height, messages_width + global messages_pad, messages_box, nodes_win, channel_win, function_win, packetlog_win stdscr.keypad(True) get_channels() @@ -245,20 +240,15 @@ def main_ui(stdscr): messages_width = width - channel_width - nodes_width channel_win = curses.newwin(height - 6, channel_width, 3, 0) - # messages_win = curses.newwin(height - 6, messages_width, 3, channel_width) + messages_box = curses.newwin(height - 6, messages_width, 3, channel_width) - messages_win = curses.newpad(1000, 1000) + messages_pad = curses.newpad(1000, 1000) packetlog_win = curses.newwin(int(height / 3), messages_width, height - int(height / 3) - 3, channel_width) nodes_win = curses.newwin(height - 6, nodes_width, 3, channel_width + messages_width) function_win = curses.newwin(3, width, height - 3, 0) draw_centered_text_field(function_win, f"↑→↓← = Select ENTER = Send ` = Settings ^P = Packet Log ESC = Quit") - # Enable scrolling for messages and nodes windows - # messages_win.scrollok(True) - # nodes_win.scrollok(True) - # channel_win.scrollok(True) - draw_channel_list() draw_node_list() draw_messages_window() @@ -266,17 +256,17 @@ def main_ui(stdscr): # Draw boxes around windows channel_win.box() entry_win.box() - # messages_win.box() nodes_win.box() + messages_box.box() function_win.box() # Refresh all windows entry_win.refresh() - messages_win.refresh(0, 0, 3, channel_width, 3 + height - 6, channel_width + messages_width - 1) + nodes_win.refresh() channel_win.refresh() function_win.refresh() - + messages_box.refresh() input_text = "" entry_win.keypad(True)