From c3e1df7b1f374c4b5e3963e98d866c5865e19ea3 Mon Sep 17 00:00:00 2001 From: hornet Date: Fri, 24 Mar 2023 00:03:49 -0400 Subject: [PATCH] menus --- main.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 66be35b..dd08ba9 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,67 @@ class MenuState: - def __init__(self, title, desc, parent): + def __init__(self, title, desc): self.title = title self.description = desc - self.parent = parent + self.parent = None self.subs = [] def add_submenu(self, menu): self.subs.append(menu) + menu.parent = self + + def display_CLI(self): + display_text = f'{self.title}\n' + if self.parent != None: + display_text += f' b. Back' + for i in range(0, len(self.subs)): + sub = self.subs[i] + display_text += f' {i}. {sub.title}\n' + display_text += f' - {sub.description}\n' + return display_text + + def nav_to_sub(self, sub_index): + if sub_index <= len(self.subs): + return self.subs[sub_index] + else: + return self + + def nav_to_parent(self): + if self.parent != None: + return self.parent + else: + return self + + + +def init_menus(): + main_menu = MenuState("NOS0S\nselect an option", "NOS0S MAIN") + net = MenuState("net attacks", "tools to attack network devices") + main_menu.add_submenu(net) + return main_menu + + + +def main(): + main_menu = init_menus() + current_menu = main_menu + while current_menu != None: + print(current_menu.display_CLI()) + res = input('> ') + if res == 'q': + break + elif res == 'b': + current_menu = current_menu.nav_to_parent() + else: + try: + selection = int(res) + current_menu = current_menu.nav_to_sub(selection) + except: + print("Invalid input. Please try again.") + + + +if __name__ == '__main__': + main() +