File: checkbox_separators.py

package info (click to toggle)
python-questionary 2.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 960 kB
  • sloc: python: 3,917; makefile: 66
file content (55 lines) | stat: -rw-r--r-- 1,344 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
# -*- coding: utf-8 -*-
"""Example for a checkbox question type.

Run example by typing `python -m examples.checkbox` in your console."""
from pprint import pprint

import questionary
from examples import custom_style_dope
from questionary import Choice
from questionary import Separator
from questionary import prompt


def ask_pystyle(**kwargs):
    # create the question object
    question = questionary.checkbox(
        "Select toppings",
        qmark="😃",
        choices=[
            Choice("foo", checked=True),
            Separator(),
            Choice("bar", disabled="nope"),
            "bazz",
            Separator("--END--"),
        ],
        style=custom_style_dope,
        **kwargs,
    )

    # prompt the user for an answer
    return question.ask()


def ask_dictstyle(**kwargs):
    questions = [
        {
            "type": "checkbox",
            "qmark": "😃",
            "message": "Select toppings",
            "name": "toppings",
            "choices": [
                {"name": "foo", "checked": True},
                Separator(),
                {"name": "bar", "disabled": "nope"},
                "bazz",
                Separator("--END--"),
            ],
        }
    ]

    return prompt(questions, style=custom_style_dope, **kwargs)


if __name__ == "__main__":
    pprint(ask_pystyle())