nos0s/menu.py

42 lines
1.1 KiB
Python
Raw Normal View History

class MenuState:
def __init__(self, title, desc):
self.title = title
self.description = desc
self.parent = None
self.subs = []
def add_submenu(self, menu):
self.subs.append(menu)
menu.parent = self
def display_CLI(self):
2023-03-26 17:58:31 +00:00
display_text = f'\n{self.title}\n'
if self.parent != None:
2023-03-26 17:58:31 +00:00
display_text += f' b. Back\n'
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'
2023-03-26 17:58:31 +00:00
return display_text, False
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
2023-03-26 17:58:31 +00:00
2023-03-26 17:58:31 +00:00
class LeafMenu(MenuState):
2023-03-26 17:58:31 +00:00
def set_action(self, action, args):
self.action = action
self.args = args
2023-03-26 17:58:31 +00:00
def display_CLI(self):
return self.action(self.args), True