diff --git a/contact/ui/contact_ui.py b/contact/ui/contact_ui.py index f449236..04a2b96 100644 --- a/contact/ui/contact_ui.py +++ b/contact/ui/contact_ui.py @@ -12,7 +12,7 @@ from contact.utilities.db_handler import get_name_from_database, update_node_inf from contact.utilities.input_handlers import get_list_input import contact.ui.default_config as config import contact.ui.dialog -from contact.ui.nav_utils import move_main_highlight, draw_main_arrows +from contact.ui.nav_utils import move_main_highlight, draw_main_arrows, highlight_line from contact.utilities.singleton import ui_state, interface_state @@ -182,7 +182,7 @@ def main_ui(stdscr: curses.window) -> None: channel_win.attrset(get_color("window_frame")) channel_win.box() channel_win.refresh() - highlight_line(False, 0, ui_state.selected_channel) + # highlight_line(False, 0, ui_state.selected_channel) refresh_pad(0) if old_window == 1: messages_win.attrset(get_color("window_frame")) @@ -194,7 +194,7 @@ def main_ui(stdscr: curses.window) -> None: nodes_win.attrset(get_color("window_frame")) nodes_win.box() nodes_win.refresh() - highlight_line(False, 2, ui_state.selected_node) + # highlight_line(False, 2, ui_state.selected_node) refresh_pad(2) if ui_state.current_window == 0: @@ -202,7 +202,7 @@ def main_ui(stdscr: curses.window) -> None: channel_win.box() channel_win.attrset(get_color("window_frame")) channel_win.refresh() - highlight_line(True, 0, ui_state.selected_channel) + # highlight_line(True, 0, ui_state.selected_channel) refresh_pad(0) elif ui_state.current_window == 1: messages_win.attrset(get_color("window_frame_selected")) @@ -216,7 +216,7 @@ def main_ui(stdscr: curses.window) -> None: nodes_win.box() nodes_win.attrset(get_color("window_frame")) nodes_win.refresh() - highlight_line(True, 2, ui_state.selected_node) + # highlight_line(True, 2, ui_state.selected_node) refresh_pad(2) # Check for Esc @@ -873,30 +873,6 @@ def refresh_pad(window: int) -> None: ) -def highlight_line(highlight: bool, window: int, line: int) -> None: - pad = nodes_pad - - color = get_color("node_list") - select_len = nodes_win.getmaxyx()[1] - 2 - - if window == 2: - node_num = ui_state.node_list[line] - node = interface_state.interface.nodesByNum[node_num] - if "isFavorite" in node and node["isFavorite"]: - color = get_color("node_favorite") - if "isIgnored" in node and node["isIgnored"]: - color = get_color("node_ignored") - - if window == 0: - pad = channel_pad - color = get_color( - "channel_selected" if (line == ui_state.selected_channel and highlight == False) else "channel_list" - ) - select_len = channel_win.getmaxyx()[1] - 2 - - pad.chgat(line, 1, select_len, color | curses.A_REVERSE if highlight else color) - - def add_notification(channel_number: int) -> None: if channel_number not in ui_state.notifications: ui_state.notifications.append(channel_number) diff --git a/contact/ui/nav_utils.py b/contact/ui/nav_utils.py index 0cb1f3a..b74199c 100644 --- a/contact/ui/nav_utils.py +++ b/contact/ui/nav_utils.py @@ -3,6 +3,18 @@ import re from contact.ui.colors import get_color from contact.utilities.control_utils import transform_menu_path from typing import Any, Optional, List, Dict +from contact.utilities.singleton import interface_state, ui_state + + +def get_node_color(node_index: int, reverse: bool = False): + node_num = ui_state.node_list[node_index] + node = interface_state.interface.nodesByNum.get(node_num, {}) + if node.get("isFavorite"): + return get_color("node_favorite", reverse=reverse) + elif node.get("isIgnored"): + return get_color("node_ignored", reverse=reverse) + return get_color("settings_default", reverse=reverse) + # Aliases Segment = tuple[str, str, bool, bool] @@ -340,26 +352,29 @@ def move_main_highlight( 0, min(ui_state.start_index[ui_state.current_window], max_index - visible_height + 1) ) - # Clear old selection - menu_pad.chgat( - old_idx, - 0, - menu_pad.getmaxyx()[1], - (get_color("settings_sensitive") if options[old_idx] in sensitive_settings else get_color("settings_default")), - ) + highlight_line(menu_win, menu_pad, old_idx, new_idx, visible_height) - # Highlight new selection + draw_main_arrows(menu_win, max_index, ui_state.start_index, ui_state.current_window) + menu_win.refresh() - menu_pad.chgat( - new_idx, - 0, - menu_pad.getmaxyx()[1], - ( - get_color("settings_sensitive", reverse=True) - if options[new_idx] in sensitive_settings - else get_color("settings_default", reverse=True) - ), - ) + +def highlight_line( + menu_win: curses.window, menu_pad: curses.window, old_idx: int, new_idx: int, visible_height: int +) -> None: + + if ui_state.current_window == 0: + color_old = ( + get_color("channel_selected") if old_idx == ui_state.selected_channel else get_color("settings_default") + ) + color_new = ( + get_color("channel_selected", reverse=True) if True else get_color("settings_default", reverse=True) + ) + menu_pad.chgat(old_idx, 1, menu_pad.getmaxyx()[1] - 4, color_old) + menu_pad.chgat(new_idx, 1, menu_pad.getmaxyx()[1] - 4, color_new) + + elif ui_state.current_window == 2: + menu_pad.chgat(old_idx, 1, menu_pad.getmaxyx()[1] - 4, get_node_color(old_idx)) + menu_pad.chgat(new_idx, 1, menu_pad.getmaxyx()[1] - 4, get_node_color(new_idx, reverse=True)) menu_win.refresh() @@ -373,9 +388,6 @@ def move_main_highlight( menu_win.getbegyx()[1] + menu_win.getmaxyx()[1] - 3, ) - draw_main_arrows(menu_win, max_index, ui_state.start_index, ui_state.current_window) - menu_win.refresh() - def draw_main_arrows(win: object, max_index: int, start_index: List[int], current_window: int) -> None: