34 lines
998 B
Python
34 lines
998 B
Python
class SelectionMenu:
|
|
|
|
def __init__(self, title):
|
|
self.title = title
|
|
self.options = []
|
|
|
|
def add_option(self, title, callback):
|
|
self.options.append({"title": title, "callback": callback})
|
|
return self
|
|
|
|
def display(self):
|
|
print("")
|
|
print(f"/--[ {self.title} ]----------------------------")
|
|
for i in range(len(self.options)):
|
|
print(f"| {i}). {self.options[i]['title']}")
|
|
print(f"\-------------------------------")
|
|
print("")
|
|
return self
|
|
|
|
def input_option(self):
|
|
try:
|
|
data = input("Selection: ")
|
|
index = int(data)
|
|
if index < 0 or index > len(self.options) - 1:
|
|
print("Please enter in a valid selection.")
|
|
return self.input_option()
|
|
return self.options[index]['callback']
|
|
except:
|
|
print("Please enter in a valid selection.")
|
|
return self.input_option()
|
|
|
|
|
|
|
|
|