From a5a7640a56ea76961ac610bdd2e86d028d52d498 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Wed, 30 Jul 2025 23:52:53 -0700 Subject: [PATCH] redraw dialog and fix traceroute --- contact/ui/contact_ui.py | 1 - contact/ui/dialog.py | 63 +++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/contact/ui/contact_ui.py b/contact/ui/contact_ui.py index 86f851d..cf0d881 100644 --- a/contact/ui/contact_ui.py +++ b/contact/ui/contact_ui.py @@ -341,7 +341,6 @@ def handle_ctrl_t(stdscr: curses.window) -> None: send_traceroute() curses.curs_set(0) # Hide cursor contact.ui.dialog.dialog( - stdscr, f"Traceroute Sent To: {get_name_from_database(ui_state.node_list[ui_state.selected_node])}", "Results will appear in messages window.\nNote: Traceroute is limited to once every 30 seconds.", ) diff --git a/contact/ui/dialog.py b/contact/ui/dialog.py index 42823d3..22bb772 100644 --- a/contact/ui/dialog.py +++ b/contact/ui/dialog.py @@ -1,14 +1,18 @@ import curses from contact.ui.colors import get_color +from contact.utilities.singleton import menu_state, ui_state def dialog(title: str, message: str) -> None: """Display a dialog with a title and message.""" + previous_window = ui_state.current_window + ui_state.current_window = 4 + curses.update_lines_cols() height, width = curses.LINES, curses.COLS - # Calculate dialog dimensions + # Parse message into lines and calculate dimensions message_lines = message.splitlines() max_line_length = max(len(l) for l in message_lines) dialog_width = max(len(title) + 4, max_line_length + 4) @@ -16,36 +20,41 @@ def dialog(title: str, message: str) -> None: x = (width - dialog_width) // 2 y = (height - dialog_height) // 2 - # Create dialog window + def draw_window(): + win.erase() + win.bkgd(get_color("background")) + win.attrset(get_color("window_frame")) + win.border(0) + + win.addstr(0, 2, title, get_color("settings_default")) + + for i, line in enumerate(message_lines): + msg_x = (dialog_width - len(line)) // 2 + win.addstr(2 + i, msg_x, line, get_color("settings_default")) + + ok_text = " Ok " + win.addstr( + dialog_height - 2, + (dialog_width - len(ok_text)) // 2, + ok_text, + get_color("settings_default", reverse=True), + ) + + win.refresh() + win = curses.newwin(dialog_height, dialog_width, y, x) - win.bkgd(get_color("background")) - win.attrset(get_color("window_frame")) - win.border(0) + draw_window() - # Add title - win.addstr(0, 2, title, get_color("settings_default")) - - # Add message (centered) - for i, line in enumerate(message_lines): - msg_x = (dialog_width - len(line)) // 2 - win.addstr(2 + i, msg_x, line, get_color("settings_default")) - - # Add centered OK button - ok_text = " Ok " - win.addstr( - dialog_height - 2, - (dialog_width - len(ok_text)) // 2, - ok_text, - get_color("settings_default", reverse=True), - ) - - # Refresh dialog window - win.refresh() - - # Get user input while True: + win.timeout(200) char = win.getch() - if char in (curses.KEY_ENTER, 10, 13, 32, 27): # Enter, space, or Esc + + if menu_state.need_redraw: + menu_state.need_redraw = False + draw_window() + + if char in (curses.KEY_ENTER, 10, 13, 32, 27): # Enter, space, Esc win.erase() win.refresh() + ui_state.current_window = previous_window return