How to mutualy exclude choices in InquirerPy

82 views Asked by At

I would like to make InquirerPy have exclusive selectors for users, so that it un-toggles options that are in a mutually exclusive grouping. I have looked through the source and don't see a way to do it, but perhaps I'm wrong.

For example; this code will succeed when 2 appropriate options are selected, but it must go though the validator and its messy.

from InquirerPy import inquirer 
from InquirerPy.base.control import Choice
from InquirerPy.separator import Separator

def display_setting_validation(sel):
    if set(sel).intersection(["compact","wide"]) and \
       set(sel).intersection(["warning", "info", "verbose"]) and \
       len(sel) == 2:
        return True
    else:
        return False


display_settings = inquirer.select(
    message="Select display settings:",
    choices=[

        Separator(),
        Choice("warning", name="Important only"),
        Choice("info", name="Informational"),
        Choice("verbose", name="Verbose"),
        Separator(),
        Choice("compact", name="Compact"),
        Choice("wide", name="Wide"),
    ],
    validate=display_setting_validation,
    multiselect=True,
).execute()
print(display_setting)

The chooser should be able to un-toggle other options to simplify this workflow. prompt_toolkit actually does it in this example.

from prompt_toolkit.shortcuts import radiolist_dialog

result = radiolist_dialog(
    title="RadioList dialog",
    text="Which breakfast would you like ?",
    values=[
        ("breakfast1", "Eggs and beacon"),
        ("breakfast2", "French breakfast"),
        ("breakfast3", "Equestrian breakfast")
    ]
).run()

Anyone know how to do this in InquirerPy ?

0

There are 0 answers