0

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 ?

Peter Moore
  • 1,632
  • 1
  • 17
  • 31
  • So, the issue is that you want TWO sets of "radio buttons" in a single list. Right? That's not possible. You just need to use two questions. You may need to use the original syntax for this; see the documentation at https://inquirerpy.readthedocs.io/en/latest/ . – Tim Roberts Jun 21 '23 at 18:09

0 Answers0