menus
This commit is contained in:
parent
29c17eb085
commit
c3e1df7b1f
60
main.py
60
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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user