|
| 1 | +from rich.console import Console |
| 2 | +from rich.panel import Panel |
| 3 | +from rich.text import Text |
| 4 | +from rich.tree import Tree |
| 5 | +from prompt_toolkit import PromptSession |
| 6 | +from prompt_toolkit.completion import WordCompleter |
| 7 | +from prompt_toolkit.styles import Style |
| 8 | +import subprocess |
| 9 | +import sys |
| 10 | +import os |
| 11 | + |
| 12 | +console = Console() |
| 13 | + |
| 14 | +commands = [ |
| 15 | + "unpack addons", "unpack gs", "unpack devtools", "unpack emulators", "unpack cybersecurity", |
| 16 | + "unpack select", "unpack gaming", "unpack noroblox", "unpack hackermode", |
| 17 | + "help", "install", "remove", "apt-install", "apt-remove", |
| 18 | + "flatpak-install", "flatpak-remove", "flatpak-update", |
| 19 | + "system logs", |
| 20 | + "run hackeros-cockpit", "run switch-to-other-session", "run update-system", "run check-updates", |
| 21 | + "run steam", "run hacker-launcher", "run hackeros-game-mode", |
| 22 | + "update", "game", "hacker-lang", "ascii", "shell", "exit" |
| 23 | +] |
| 24 | + |
| 25 | +completer = WordCompleter(commands, ignore_case=True) |
| 26 | + |
| 27 | +style = Style.from_dict({ |
| 28 | + 'prompt': 'cyan bold', |
| 29 | +}) |
| 30 | + |
| 31 | +def display_command_list(): |
| 32 | + console.clear() |
| 33 | + title = Text("Hacker Shell - Commands", style="bold magenta") |
| 34 | + tree = Tree("Available Commands", style="bold green") |
| 35 | + |
| 36 | + unpack = tree.add("unpack: Unpack various toolsets", style="cyan") |
| 37 | + unpack.add("addons, gs, devtools, emulators, cybersecurity, select, gaming, noroblox, hackermode") |
| 38 | + |
| 39 | + tree.add("help: Display help") |
| 40 | + tree.add("install <package>") |
| 41 | + tree.add("remove <package>") |
| 42 | + tree.add("apt-install <package>") |
| 43 | + tree.add("apt-remove <package>") |
| 44 | + tree.add("flatpak-install <package>") |
| 45 | + tree.add("flatpak-remove <package>") |
| 46 | + tree.add("flatpak-update") |
| 47 | + |
| 48 | + system = tree.add("system: System commands", style="cyan") |
| 49 | + system.add("logs") |
| 50 | + |
| 51 | + run = tree.add("run: Run scripts", style="cyan") |
| 52 | + run.add("hackeros-cockpit, switch-to-other-session, update-system, check-updates, steam, hacker-launcher, hackeros-game-mode") |
| 53 | + |
| 54 | + tree.add("update") |
| 55 | + tree.add("game") |
| 56 | + tree.add("hacker-lang") |
| 57 | + tree.add("ascii") |
| 58 | + tree.add("shell") |
| 59 | + tree.add("exit: Exit the shell") |
| 60 | + |
| 61 | + panel = Panel(tree, title=title, expand=False, border_style="green") |
| 62 | + console.print(panel) |
| 63 | + |
| 64 | +def run_hacker_command(cmd): |
| 65 | + if cmd.strip() == "": |
| 66 | + return |
| 67 | + if cmd == "exit": |
| 68 | + sys.exit(0) |
| 69 | + try: |
| 70 | + result = subprocess.run(["hacker"] + cmd.split(), capture_output=True, text=True) |
| 71 | + if result.returncode == 0: |
| 72 | + console.print(result.stdout, style="green") |
| 73 | + else: |
| 74 | + console.print(result.stderr, style="red") |
| 75 | + except Exception as e: |
| 76 | + console.print(f"Error executing command: {e}", style="red") |
| 77 | + |
| 78 | +def main(): |
| 79 | + session = PromptSession(completer=completer, style=style) |
| 80 | + while True: |
| 81 | + display_command_list() |
| 82 | + try: |
| 83 | + cmd = session.prompt('> ') |
| 84 | + run_hacker_command(cmd) |
| 85 | + except KeyboardInterrupt: |
| 86 | + continue |
| 87 | + except EOFError: |
| 88 | + break |
| 89 | + |
| 90 | +if __name__ == "__main__": |
| 91 | + main() |
1 | 92 |
|
0 commit comments