From 4c4c0d553eadf0110a8b1c2fe50038f37d2c110a Mon Sep 17 00:00:00 2001 From: Russell Schmidt Date: Thu, 16 Jan 2025 12:07:29 -0600 Subject: [PATCH] Add dialog confirmation when traceroute sent --- ui/curses_ui.py | 4 ++++ ui/dialog.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 ui/dialog.py diff --git a/ui/curses_ui.py b/ui/curses_ui.py index 394284a..47f88fc 100644 --- a/ui/curses_ui.py +++ b/ui/curses_ui.py @@ -4,6 +4,7 @@ import globals from utilities.utils import get_name_from_number, get_channels from settings import settings from message_handlers.tx_handler import send_message, send_traceroute +import ui.dialog def add_notification(channel_number): handle_notification(channel_number, add=True) @@ -327,6 +328,9 @@ def main_ui(stdscr): # Check for Ctrl + t elif char == 20: send_traceroute() + curses.curs_set(0) # Hide cursor + ui.dialog.dialog(stdscr, "Traceroute Sent", "Results will appear in messages window") + curses.curs_set(1) # Show cursor again elif char == curses.KEY_ENTER or char == 10 or char == 13: if globals.current_window == 2: diff --git a/ui/dialog.py b/ui/dialog.py new file mode 100644 index 0000000..c8bbb07 --- /dev/null +++ b/ui/dialog.py @@ -0,0 +1,34 @@ +import curses + +def dialog(stdscr, title, message): + height, width = stdscr.getmaxyx() + + # Calculate dialog dimensions + dialog_width = max(len(title) + 4, len(message) + 4) + dialog_height = 5 + x = (width - dialog_width) // 2 + y = (height - dialog_height) // 2 + + # Create dialog window + win = curses.newwin(dialog_height, dialog_width, y, x) + win.border(0) + + # Add title + win.addstr(0, 2, title) + + # Add message + win.addstr(2, 2, message) + + # Add button + win.addstr(dialog_height - 2, (dialog_width - 4) // 2, " Ok ") + + # Refresh dialog window + win.refresh() + + # Get user input + while True: + char = win.getch() + if char == curses.KEY_ENTER or char == 10 or char == 13: + win.clear() + win.refresh() + return