

def prompt_for_choice(choices, prompt=None, console=default_console, default=(- 1), input_kwargs=None):
    "\n    :param choices: list of choices. should be a list of str\n    :type choices: list[str]\n    :param prompt: the prompt to be shown while asking user. default is 'choose one from above options'\n    :type prompt: str\n    :param console: console used to output\n    :type console: taskr.terminal.Console\n    :param default: default option of these choice. any value less than 0 means no default value\n    :type default: int\n    :return: the value use choose, or the default one\n    :rtype: int\n    "
    assert (default < len(choices)), 'Default option is great than the number of choices'
    has_default = (default >= 0)
    zero_paddings = int(math.ceil(math.log10(len(choices))))
    choice_template = '{{}}{{:{}d}}) {{}}'.format(zero_paddings)
    if has_default:
        default_prefix = '* '
        non_default_prefix = '  '
    else:
        default_prefix = non_default_prefix = ''
    for (i, choice) in enumerate(choices):
        console.show(choice_template.format((default_prefix if (i == default) else non_default_prefix), i, choice))

    def choice_validator(value):
        if (value < len(choices)):
            return value
        else:
            raise ValueError('The index is greater than the number of choices')
    input_kwargs = (input_kwargs or {
        
    })
    if has_default:
        input_kwargs['default'] = default
    return console.input(prompt=(prompt or 'Choose one from above options'), validators=[integer_validator(error_message='Choose a number'), choice_validator], repeat_until_valid=True, **input_kwargs)

dataset/ETHPy150Open sodastsai/taskr/taskr/contrib/cli.py prompt_for_choice/original