implemented short menu system too

This commit is contained in:
Luxferre
2026-01-04 14:41:54 +02:00
parent d2009dd65c
commit 7eb45a4f0b
3 changed files with 32 additions and 3 deletions
+25
View File
@@ -64,3 +64,28 @@ def menu(choices, max_size = 10):
else:
print('Invalid choice!')
return menu(choices)
def shortmenu(choices, suffix=': '):
letters = {}
cmap = []
for c in choices:
l = '?'
cl = len(c)
i = 0
while i < cl:
l = c[i].lower()
if l not in letters:
break
i += 1
if i == 0:
letters[l] = (c, l + ')' + c[1:])
cmap.append(letters[l][1])
elif i < cl:
letters[l] = (c, c[0:i] + '(' + l + ')' + c[i+1:])
cmap.append(letters[l][1])
prompt = ' '.join(cmap) + suffix
res = input(prompt).strip()[0].lower()
if res in letters:
return (res, letters[res][0])
else:
return ('', '')