Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add channel and node search feature #117

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions ui/curses_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,50 @@ def draw_packetlog_win():
packetlog_win.box()
packetlog_win.refresh()

def search(win):
start_idx = globals.selected_node
l = globals.node_list
select_func = select_node

if win == 0:
start_idx = globals.selected_channel
l = globals.channel_list
select_func = select_channel

search_text = ""
entry_win.erase()

while True:
draw_centered_text_field(entry_win, f"Search: {search_text}", 0, get_color("input"))
char = entry_win.get_wch()

if char in (chr(27), chr(curses.KEY_ENTER), chr(10), chr(13)):
break
elif char == "\t":
start_idx = globals.selected_node + 1 if win == 2 else globals.selected_channel + 1
elif char in (curses.KEY_BACKSPACE, chr(127)):
if search_text:
search_text = search_text[:-1]
y, x = entry_win.getyx()
entry_win.move(y, x - 1)
entry_win.addch(' ') #
entry_win.move(y, x - 1)
entry_win.erase()
entry_win.refresh()
elif isinstance(char, str):
search_text += char

search_text_caseless = search_text.casefold()

for i, n in enumerate(l[start_idx:] + l[:start_idx]):
if isinstance(n, int) and search_text_caseless in get_name_from_database(n, 'long').casefold() \
or isinstance(n, int) and search_text_caseless in get_name_from_database(n, 'short').casefold() \
or search_text_caseless in str(n).casefold():
select_func((i + start_idx) % len(l))
break

entry_win.erase()

def handle_resize(stdscr, firstrun):
global messages_pad, messages_box, nodes_pad, nodes_box, channel_pad, channel_box, function_win, packetlog_win, entry_win

Expand Down Expand Up @@ -671,6 +715,10 @@ def main_ui(stdscr):
draw_channel_list()
draw_messages_window()

elif char == chr(31):
if(globals.current_window == 2 or globals.current_window == 0):
search(globals.current_window)

else:
# Append typed character to input text
if(isinstance(char, str)):
Expand Down