-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathscore_starter
More file actions
executable file
·112 lines (91 loc) · 2.99 KB
/
score_starter
File metadata and controls
executable file
·112 lines (91 loc) · 2.99 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
import os
import sys
import termios
import tty
import subprocess
import argparse
# ================== CONFIG ==================
# Each entry: (description, command, name)
mEntries = [
("Run QNX x86_64 QEMU", "bazel --output_base=build/qnx-x86_64 run --config qnx-x86_64 //images/qnx_x86_64:run", "qnx-x86_64"),
("Run Linux x86_64 Docker", "bazel --output_base=build/linux-x86_64 run --config linux-x86_64 //images/linux_x86_64:run", "linux-x86_64"),
("Run Elektrobit Corbos aarch64 QEMU",
"bazel --output_base=build/eb-aarch64 build --config eb-aarch64 //images/ebclfsa_aarch64/scrample_integration:run", "eb-aarch64"),
("Run Autosd x86_64 QEMU",
"bazel --output_base=build/autosd-x86_64 run --config autosd-x86_64 //images/autosd_x86_64:run", "autosd-x86_64"),
("Exit", "exit 0", "exit"),
]
# ================== INTERNAL ==================
mSelected = 0
mCount = len(mEntries)
def clear():
os.system("clear")
def draw_menu():
clear()
print("Use ↑ ↓ to navigate, Enter to run, q to quit\n")
for i, (desc, _, _) in enumerate(mEntries):
if i == mSelected:
# inverse video
print(f" \033[7m {desc} \033[0m")
else:
print(f" {desc}")
def run_entry(entry):
desc, cmd, _ = entry
clear()
print(f"▶ {desc}\n")
if cmd.startswith("exit"):
sys.exit(0)
# Run command in user's shell
print("Running ", cmd)
result = subprocess.call(cmd, shell=True)
sys.exit(result)
def read_key():
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch1 = sys.stdin.read(1)
if ch1 == "\x1b":
ch2 = sys.stdin.read(1)
ch3 = sys.stdin.read(1)
return ch1 + ch2 + ch3
return ch1
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
def interactive_loop():
global mSelected
while True:
draw_menu()
key = read_key()
if key == "\x1b[A": # Up
mSelected = (mSelected - 1) % mCount
elif key == "\x1b[B": # Down
mSelected = (mSelected + 1) % mCount
elif key in ("\r", "\n"): # Enter
run_entry(mEntries[mSelected])
elif key == "q":
sys.exit(0)
# ================== MAIN ==================
def main():
parser = argparse.ArgumentParser(
description="Interactive build/run menu script",
epilog="Use -r NAME to run a specific entry directly."
)
parser.add_argument(
"-r", "--run",
help="Run a specific menu entry by name",
choices=[name for _, _, name in mEntries]
)
args = parser.parse_args()
if args.run:
# Find the entry by name and run it
entry = next((e for e in mEntries if e[2] == args.run), None)
if entry is None:
print(f"Unknown entry: {args.run}")
sys.exit(1)
run_entry(entry)
else:
interactive_loop()
if __name__ == "__main__":
main()