(stdscr)
| 765 | |
| 766 | |
| 767 | def curses_menu(stdscr): |
| 768 | curses.start_color() |
| 769 | curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) |
| 770 | curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_WHITE) |
| 771 | |
| 772 | menu_style = "list" # "list" or "number" |
| 773 | |
| 774 | menu_items = [ |
| 775 | "Install example plugins", |
| 776 | "Check/start Tor", |
| 777 | "Crawl a URL", |
| 778 | "Search Ahmia", |
| 779 | "Load & run plugins on last results", |
| 780 | "Export last results (json/csv/txt)", |
| 781 | "Choose Menu Style", |
| 782 | "Exit" |
| 783 | ] |
| 784 | current_selection = 0 |
| 785 | status_msg = "" |
| 786 | while True: |
| 787 | draw_menu(stdscr, current_selection, menu_items, "TorBot All-in-One", status_msg, menu_style) |
| 788 | status_msg = "" |
| 789 | key = stdscr.getch() |
| 790 | |
| 791 | selected_action_index = -1 # Flag for no action |
| 792 | |
| 793 | if key == ord('q'): |
| 794 | break |
| 795 | |
| 796 | if menu_style == "list": |
| 797 | if key == curses.KEY_UP: |
| 798 | current_selection = (current_selection - 1) % len(menu_items) |
| 799 | elif key == curses.KEY_DOWN: |
| 800 | current_selection = (current_selection + 1) % len(menu_items) |
| 801 | elif key == ord('\n') or key == ord(' '): |
| 802 | selected_action_index = current_selection |
| 803 | |
| 804 | elif menu_style == "number": |
| 805 | if ord('1') <= key <= ord(str(len(menu_items))): |
| 806 | try: |
| 807 | # '1' maps to index 0 |
| 808 | selected_action_index = int(chr(key)) - 1 |
| 809 | except ValueError: |
| 810 | pass # Not a valid number |
| 811 | |
| 812 | # --- Handle the selected action --- |
| 813 | if selected_action_index == -1: |
| 814 | continue # No action selected, loop again |
| 815 | |
| 816 | # --- Action processing --- |
| 817 | if selected_action_index == 0: # Install plugins |
| 818 | installed = install_plugins() |
| 819 | status_msg = f"Installed {len(installed)} plugins: {', '.join(installed)}" |
| 820 | elif selected_action_index == 1: # Check/start Tor |
| 821 | if is_tor_running(): |
| 822 | status_msg = "[*] Tor appears to be running (SOCKS open)." |
| 823 | else: |
| 824 | ok, msg = try_start_tor_background() |
nothing calls this directly
no test coverage detected