I broke the self.choices collection code into two parts:
append the choices in "normalized" form
select an appropriate default
This requires mutation of the key, so I changed the type from tuple to list, which in this case is functionally equivalent except that tuples are immutable.
The other piece that was missing had to do with h/H keys being handled differently than a standard choice (i.e., the _help_active flag is set), so I added a conditional in set_answer for that, which allows users to hit Enter without None becoming the selected value. The choice to use a special "__HELP__" value is to avoid disallowing users to choose None as a value, which also seems to be how KeyboardInterrupt (Ctrl-C) is handled.
I broke the
self.choices
collection code into two parts:This requires mutation of the key, so I changed the type from
tuple
tolist
, which in this case is functionally equivalent except that tuples are immutable.The other piece that was missing had to do with
h
/H
keys being handled differently than a standard choice (i.e., the_help_active
flag is set), so I added a conditional inset_answer
for that, which allows users to hitEnter
withoutNone
becoming the selected value. The choice to use a special"__HELP__"
value is to avoid disallowing users to chooseNone
as a value, which also seems to be howKeyboardInterrupt
(Ctrl-C) is handled.