initial build
This commit is contained in:
34
ui/selection_menu.py
Normal file
34
ui/selection_menu.py
Normal file
@@ -0,0 +1,34 @@
|
||||
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()
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user