2015-06-14 22:31:01 +00:00
|
|
|
import curses
|
2024-04-27 21:00:01 +00:00
|
|
|
from time import sleep
|
2024-04-28 01:26:44 +00:00
|
|
|
from fallout_functions import slowWrite, centeredWrite, NEWLINE, SPACE, addSound
|
2015-06-14 22:31:01 +00:00
|
|
|
|
|
|
|
###################### Functions ############################
|
|
|
|
|
2024-04-27 21:00:01 +00:00
|
|
|
def makeSelection(scr, SELECTIONS, MSGS):
|
2015-06-14 22:31:01 +00:00
|
|
|
"""
|
|
|
|
ALlow the user to select an option
|
|
|
|
Returns the line number of the users selection starting at 0
|
|
|
|
"""
|
|
|
|
inchar = 0
|
|
|
|
selection = 0
|
|
|
|
selection_count = len(SELECTIONS)
|
|
|
|
selection_start_y = scr.getyx()[0]
|
|
|
|
width = scr.getmaxyx()[1]
|
2024-04-27 21:00:01 +00:00
|
|
|
|
2024-04-28 01:26:44 +00:00
|
|
|
while inchar not in [NEWLINE, SPACE]:
|
2015-06-14 22:31:01 +00:00
|
|
|
# move to start of selections and hightlight current selection
|
|
|
|
scr.move(selection_start_y, 0)
|
|
|
|
line = 0
|
|
|
|
for sel in SELECTIONS:
|
|
|
|
whole_line = '> ' + SELECTIONS[line]
|
|
|
|
space = width - len(whole_line) % width
|
|
|
|
whole_line += ' ' * space
|
2024-04-27 21:00:01 +00:00
|
|
|
|
2015-06-14 22:31:01 +00:00
|
|
|
if line == selection:
|
|
|
|
scr.addstr(whole_line, curses.A_REVERSE)
|
|
|
|
else:
|
|
|
|
scr.addstr(whole_line)
|
|
|
|
line += 1
|
|
|
|
scr.refresh()
|
|
|
|
|
|
|
|
inchar = scr.getch()
|
|
|
|
|
|
|
|
# move up and down
|
|
|
|
if inchar == curses.KEY_UP and selection > 0:
|
|
|
|
selection -= 1
|
2024-04-27 21:00:01 +00:00
|
|
|
addSound("keyenter")
|
2015-06-14 22:31:01 +00:00
|
|
|
elif inchar == curses.KEY_DOWN and selection < selection_count - 1:
|
|
|
|
selection += 1
|
2024-04-27 21:00:01 +00:00
|
|
|
addSound("keyenter")
|
2024-04-27 21:29:03 +00:00
|
|
|
addSound("keyenter")
|
2024-04-27 21:00:01 +00:00
|
|
|
if MSGS and MSGS[selection]:
|
|
|
|
whole_line = '> ' + MSGS[selection]
|
|
|
|
space = width - len(whole_line) % width
|
|
|
|
whole_line += ' ' * space
|
|
|
|
scr.addstr(' ' * width)
|
|
|
|
scr.addstr(whole_line)
|
|
|
|
scr.refresh()
|
|
|
|
sleep(2)
|
2015-06-14 22:31:01 +00:00
|
|
|
return selection
|
|
|
|
|
2024-04-27 21:00:01 +00:00
|
|
|
|
|
|
|
def runSelection(scr, CENTERED_HEADERS, OTHER_HEADERS, OPTIONS, MESSAGES):
|
2015-06-14 22:31:01 +00:00
|
|
|
"""
|
|
|
|
Print the selections and allow the user to select one
|
|
|
|
"""
|
|
|
|
curses.use_default_colors()
|
|
|
|
scr.erase()
|
|
|
|
scr.move(0, 0)
|
|
|
|
curses.curs_set(0)
|
|
|
|
curses.noecho()
|
|
|
|
|
|
|
|
width = scr.getmaxyx()[1]
|
|
|
|
|
|
|
|
for header in CENTERED_HEADERS:
|
|
|
|
centeredWrite(scr, header + '\n')
|
|
|
|
|
|
|
|
for header in OTHER_HEADERS:
|
|
|
|
slowWrite(scr, header + '\n')
|
|
|
|
|
2021-05-19 18:47:24 +00:00
|
|
|
for i in range(width):
|
2015-06-14 22:31:01 +00:00
|
|
|
scr.addch(curses.ACS_BSBS)
|
|
|
|
scr.refresh()
|
|
|
|
|
2024-04-27 21:00:01 +00:00
|
|
|
return makeSelection(scr, OPTIONS, MESSAGES)
|
2015-06-14 22:31:01 +00:00
|
|
|
|
2024-04-27 21:00:01 +00:00
|
|
|
def beginSelection(center, other, options, messages = []):
|
2015-06-14 22:31:01 +00:00
|
|
|
"""
|
|
|
|
Initialize curses and start the boot process
|
|
|
|
"""
|
2024-04-27 21:00:01 +00:00
|
|
|
res = curses.wrapper(runSelection, center, other, options, messages)
|
2015-06-14 22:31:01 +00:00
|
|
|
return res
|