def ask_choice(choices, input_text, return_int=False):
    """Ask the user to choose from a list of choices

    """
    ui.info(ui.green, "::", ui.reset, input_text)
    for i, choice in enumerate(choices, start=1):
        if i == 1:
            choice += " \t(default)"
        ui.info("  ", ui.blue, "%i" % i, ui.reset, choice)
    keep_asking = True
    res = None
    while keep_asking:
        try:
            answer = read_input()
        except KeyboardInterrupt:
            break
        if not answer:
            return choices[0]
        try:
            index = int(answer)
        except ValueError:
            print "Please enter number"
            continue
        if index not in range(1, len(choices)+1):
            print "%i is out of range" % index
            continue
        res = choices[index-1]
        keep_asking = False

    if return_int:
        return index-1

    return res
dataset/ETHPy150Open aldebaran/qibuild/python/qisys/interact.py/ask_choice/original