D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
3
/
cwd
/
opt
/
custom-ns
/
Filename :
select_menu.py
back
Copy
"""Just a simple ncurses selection menu. May be moved to rads.common someday depending on usefulness""" from blessings import Terminal from rads._input import get_keypress def select_menu(question, options, selected=0): """Display an ncurses menu with 'question'<string> as the header and 'options'<list> to choose from""" if len(options) == 0: return None width = sorted([len(x) for x in options])[-1] + 2 term = Terminal() with term.fullscreen(): while True: print(term.clear()) with term.location(4, 1): print(term.bold(question)) for index, option in enumerate(options): with term.location(4, index + 2): if index == selected: print(term.bold_black_on_white(option.ljust(width))) else: print(option.ljust(width)) key = get_keypress() if key == 'ENTER': return options[selected] if key == 'ARROW_UP': selected -= 1 elif key == 'ARROW_DN': selected += 1 selected = selected % len(options)