diff --git a/contact/ui/control_ui.py b/contact/ui/control_ui.py index 262652d..235655e 100644 --- a/contact/ui/control_ui.py +++ b/contact/ui/control_ui.py @@ -1,5 +1,6 @@ import base64 import curses +import ipaddress import logging import os import sys @@ -122,6 +123,18 @@ def display_menu() -> tuple[object, object]: full_key = ".".join(transformed_path + [option]) display_name = field_mapping.get(full_key, option) + if full_key.startswith("config.network.ipv4_config.") and option in {"ip", "gateway", "subnet", "dns"}: + if isinstance(current_value, int): + try: + current_value = str(ipaddress.IPv4Address(current_value)) + except ipaddress.AddressValueError: + pass + elif isinstance(current_value, str) and current_value.isdigit(): + try: + current_value = str(ipaddress.IPv4Address(int(current_value))) + except ipaddress.AddressValueError: + pass + display_option = f"{display_name}"[: w // 2 - 2] display_value = f"{current_value}"[: w // 2 - 4] diff --git a/contact/utilities/input_handlers.py b/contact/utilities/input_handlers.py index 3233488..edb9d7c 100644 --- a/contact/utilities/input_handlers.py +++ b/contact/utilities/input_handlers.py @@ -536,7 +536,7 @@ def get_fixed32_input(current_value: int) -> int: curses.napms(1500) user_input = "" - elif key in (curses.KEY_BACKSPACE, 127): + elif key in (curses.KEY_BACKSPACE, curses.KEY_DC, 127, 8, "\b", "\x7f"): user_input = user_input[:-1] else: diff --git a/contact/utilities/save_to_radio.py b/contact/utilities/save_to_radio.py index b3bfdc3..0a42e8e 100644 --- a/contact/utilities/save_to_radio.py +++ b/contact/utilities/save_to_radio.py @@ -112,16 +112,23 @@ def save_changes(interface, modified_settings, menu_state): else: config_category = None + # Resolve the target config container, including nested sub-messages (e.g., network.ipv4_config) + config_container = None + if hasattr(node.localConfig, config_category): + config_container = getattr(node.localConfig, config_category) + elif hasattr(node.moduleConfig, config_category): + config_container = getattr(node.moduleConfig, config_category) + else: + logging.warning(f"Config category '{config_category}' not found in config.") + return + + if len(menu_state.menu_path) >= 4: + nested_key = menu_state.menu_path[3] + if hasattr(config_container, nested_key): + config_container = getattr(config_container, nested_key) + for config_item, new_value in modified_settings.items(): - # Check if the category exists in localConfig - if hasattr(node.localConfig, config_category): - config_subcategory = getattr(node.localConfig, config_category) - # Check if the category exists in moduleConfig - elif hasattr(node.moduleConfig, config_category): - config_subcategory = getattr(node.moduleConfig, config_category) - else: - logging.warning(f"Config category '{config_category}' not found in config.") - continue + config_subcategory = config_container # Check if the config_item exists in the subcategory if hasattr(config_subcategory, config_item):