Module: check_mk
Branch: master
Commit: 0d67adda933ebdcf4f543d07eacaa49e866700de
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0d67adda933ebd…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Oct 19 13:46:53 2017 +0200
werk script: Allow choices where all identifying characters are already in use
Change-Id: Ia181142bc06327fdddb4cf83a283dd0126b58f0a
---
werk | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/werk b/werk
index f52e532..c5840e1 100755
--- a/werk
+++ b/werk
@@ -448,17 +448,30 @@ def getch():
return ch
def input_choice(what, choices):
+ next_index = 0
ctc = {}
texts = []
for choice in choices:
if type(choice) == tuple:
choice = choice[0]
+
+ added = False
+
+ # Find an identifying character for the input choice. In case all possible
+ # characters are already used start using unique numbers
for c in str(choice):
if c not in ".-_/" and c not in ctc:
ctc[c] = choice
texts.append(str(choice).replace(c, tty_bold + c + tty_normal, 1))
+ added = True
break
+ if not added:
+ ctc["%s" % next_index] = choice
+ texts.append("%s:%s" % ("%s%d%s" % (tty_bold, next_index,
tty_normal), choice))
+ next_index += 1
+
+
while True:
sys.stdout.write("%s (%s): " % (what, ", ".join(texts)))
sys.stdout.flush()