Separator¶
You can use Separator
to effectively group choices visually in the
following types of prompts which involves list of choices:
pages/prompts/list:ListPrompt
pages/prompts/rawlist:RawlistPrompt
pages/prompts/expand:ExpandPrompt
pages/prompts/checkbox:CheckboxPrompt
- class InquirerPy.separator.Separator(line='---------------')[source]
A non selectable choice that can be used as part of the choices argument in list type prompts.
It can be used to create some visual separations between choices in list type prompts.
- Parameters
line (str) – Content to display as the separator.
- Return type
None
Example
>>> from InquirerPy import inquirer >>> choices = [1, 2, Separator(), 3] >>> inquirer.select(message="", choices=choices)
Classic Syntax
"""
? Select regions: █
Sydney
❯ Singapore
--------------- <- Separator
us-east-1
us-east-2
"""
from InquirerPy import prompt
from InquirerPy.base.control import Choice
from InquirerPy.separator import Separator
result = prompt(
questions=[
{
"type": "list",
"message": "Select regions:",
"choices": [
Choice("ap-southeast-2", name="Sydney"),
Choice("ap-southeast-1", name="Singapore"),
Separator(),
"us-east-1",
"us-east-2",
],
"multiselect": True,
"transformer": lambda result: f"{len(result)} region{'s' if len(result) > 1 else ''} selected",
},
],
)
Alternate Syntax
"""
? Select regions: █
Sydney
❯ Singapore
--------------- <- Separator
us-east-1
us-east-2
"""
from InquirerPy import inquirer
from InquirerPy.base.control import Choice
from InquirerPy.separator import Separator
region = inquirer.select(
message="Select regions:",
choices=[
Choice("ap-southeast-2", name="Sydney"),
Choice("ap-southeast-1", name="Singapore"),
Separator(),
"us-east-1",
"us-east-2",
],
multiselect=True,
transformer=lambda result: f"{len(result)} region{'s' if len(result) > 1 else ''} selected",
).execute()