-
Notifications
You must be signed in to change notification settings - Fork 11
/
fallout_selection.py
97 lines (78 loc) · 2.3 KB
/
fallout_selection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import curses
from fallout_functions import slowWrite
from fallout_functions import centeredWrite
from fallout_functions import NEWLINE
####################### text strings ########################
CENTERED_HEADERS = (
'ROBCO INDUSTRIES UNIFIED OPERATING SYSTEM',
'COPYRIGHT 2075-2077 ROBCO INDUSTRIES',
'-SERVER 6-',
''
)
OTHER_HEADERS = (
'\tSoftLock Solutions, Inc',
'"Your Security is Our Security"',
'>\\ Welcome, USER',
''
)
SELECTIONS = (
'Disengage Lock',
'Deactivate Turrets',
'Read Log'
)
###################### Functions ############################
def makeSelection(scr):
"""
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]
while inchar != NEWLINE:
# 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
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
elif inchar == curses.KEY_DOWN and selection < selection_count - 1:
selection += 1
return selection
def runSelection(scr):
"""
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')
for i in range(width):
scr.addch(curses.ACS_BSBS)
scr.refresh()
return makeSelection(scr)
def beginSelection():
"""
Initialize curses and start the boot process
"""
res = curses.wrapper(runSelection)
return res