def prompt_for_choice(choices, prompt=None, console=default_console, default=-1, input_kwargs=None):
    """
    :param choices: list of choices. should be a list of str
    :type choices: list[str]
    :param prompt: the prompt to be shown while asking user. default is 'choose one from above options'
    :type prompt: str
    :param console: console used to output
    :type console: taskr.terminal.Console
    :param default: default option of these choice. any value less than 0 means no default value
    :type default: int
    :return: the value use choose, or the default one
    :rtype: int
    """
    assert default < len(choices), 'Default option is great than the number of choices'
    has_default = default >= 0

    # Show options
    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))

    # Ask
    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