21 lines
771 B
Python
21 lines
771 B
Python
from simple_term_menu import TerminalMenu
|
|
|
|
|
|
def terminal_menu(menu_options, menu_title, clear_screen=False):
|
|
if isinstance(menu_options, list):
|
|
menu = TerminalMenu(menu_options, clear_screen=clear_screen, title=menu_title)
|
|
entry_index = menu.show()
|
|
if entry_index is not None:
|
|
return menu_options[entry_index]
|
|
|
|
elif isinstance(menu_options, dict):
|
|
menu = TerminalMenu(list(menu_options.keys()), clear_screen=True, title=menu_title)
|
|
entry_index = menu.show()
|
|
if entry_index is not None:
|
|
selected_key = list(menu_options.keys())[entry_index]
|
|
return selected_key, menu_options[selected_key]
|
|
return None
|
|
|
|
else:
|
|
raise ValueError("Input must be list or dict.")
|
|
|