File: input.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 (132 lines) | stat: -rw-r--r-- 2,682 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# text

A text prompt that accepts user input.

## Example

![demo](https://assets.kazhala.me/InquirerPy/InquirerPy-input.gif)

<details>
  <summary>Classic Syntax (PyInquirer)</summary>

```{eval-rst}
.. literalinclude :: ../../../examples/classic/input.py
   :language: python
```

</details>

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

```{eval-rst}
.. literalinclude :: ../../../examples/alternate/input.py
   :language: python
```

</details>

## Keybindings

```{seealso}
{ref}`pages/kb:Keybindings`
```

```{include} ../kb.md
:start-after: <!-- start kb -->
:end-before: <!-- end kb -->
```

Besides the default keybindings and input buffer keybindings, if you have autocompletion enabled, you can use
`ctrl-space` to trigger completion window popup.

```
{
    "completion": [{"key": "c-space"}]  # force completion popup
}
```

## Auto Completion

```{tip}
Use `ctrl-space` to force completion window popup.
```

You can add auto completion to the prompt via the parameter/key `completer`. Provide a {class}`~prompt_toolkit.completion.Completer` class or a dictionary of words to enable auto-completion of the prompt.
Below is a simple {class}`dict` completer.

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

```python
from InquirerPy import prompt

completer = {
    "hello": {
        "world": None
    },
    "foo": {
        "boo": None
    },
    "fizz": {
        "bazz": None
    }
}

questions = [
    {
        "type": "input",
        "message": "FooBoo:",
        "completer": completer
    }
]

result = prompt(questions=questions)
```

</details>

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

```python
from InquirerPy import inquirer

completer = {
    "hello": {
        "world": None
    },
    "foo": {
        "boo": None
    },
    "fizz": {
        "bazz": None
    }
}

result = inquirer.text(message="FooBoo:", completer=completer).execute()
```

</details>

Checkout `prompt_toolkit` [documentation](https://python-prompt-toolkit.readthedocs.io/en/master/pages/asking_for_input.html#autocompletion)
for more examples and information on how to create more dynamic/complex completer.

## Multi-line Input

By setting the parameter `multiline` to `True`, the prompt will change from single line input to multiple line input.
While `multiline` is `True`, `enter` will causing a new line to be used instead of finish answering the question. Press
`esc` and then press `enter` to finish answer the question.

```{code-block} python
from InquirerPy import inquirer

result = inquirer.text(message="FooBoo:", multiline=True).execute()
```

## Reference

```{eval-rst}
.. autoclass:: InquirerPy.prompts.input.InputPrompt
    :noindex:
```