(question, choice, default='', show_choice=True, multi_choice=False)
| 238 | |
| 239 | |
| 240 | def user_choice(question, choice, default='', show_choice=True, multi_choice=False): |
| 241 | choices = [ch.lower() if ch.upper() == default.upper() else ch.lower() for ch in choice] |
| 242 | |
| 243 | result = '' |
| 244 | while True: |
| 245 | pr = question |
| 246 | if show_choice: |
| 247 | pr = pr + ' [' + '/'.join(choices) + ']' |
| 248 | |
| 249 | pr = pr + ': ' |
| 250 | result = input(pr) |
| 251 | |
| 252 | if len(result) == 0: |
| 253 | return default |
| 254 | |
| 255 | if multi_choice: |
| 256 | s1 = set([x.lower() for x in choices]) |
| 257 | s2 = set([x.lower() for x in result]) |
| 258 | if s2 < s1: |
| 259 | return ''.join(s2) |
| 260 | pass |
| 261 | elif any(map(lambda x: x.upper() == result.upper(), choices)): |
| 262 | return result |
| 263 | |
| 264 | logging.error('Error: invalid input') |
| 265 | |
| 266 | |
| 267 | def raise_parse_exception(m): |
no test coverage detected