File: separator.md

package info (click to toggle)
python-inquirerpy 0.3.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,088 kB
  • sloc: python: 9,463; makefile: 15
file content (83 lines) | stat: -rw-r--r-- 1,947 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Separator

You can use {class}`~InquirerPy.separator.Separator` to effectively group {ref}`pages/dynamic:choices` visually in the
following types of prompts which involves list of choices:

- {ref}`pages/prompts/list:ListPrompt`
- {ref}`pages/prompts/rawlist:RawlistPrompt`
- {ref}`pages/prompts/expand:ExpandPrompt`
- {ref}`pages/prompts/checkbox:CheckboxPrompt`

```{eval-rst}
.. autoclass:: InquirerPy.separator.Separator
    :noindex:
```

<details>
  <summary>Classic Syntax</summary>

```python
"""
? 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",
        },
    ],
)
```

</details>

<details open>
  <summary>Alternate Syntax</summary>

```python
"""
? 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()
```

</details>