PyInquirer 1.0.4__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- PyInquirer/__init__.py +29 -0
- PyInquirer/color_print.py +41 -0
- PyInquirer/prompt.py +106 -0
- PyInquirer/prompts/__init__.py +0 -0
- PyInquirer/prompts/checkbox.py +256 -0
- PyInquirer/prompts/common.py +92 -0
- PyInquirer/prompts/confirm.py +86 -0
- PyInquirer/prompts/editor.py +182 -0
- PyInquirer/prompts/expand.py +195 -0
- PyInquirer/prompts/input.py +62 -0
- PyInquirer/prompts/list.py +191 -0
- PyInquirer/prompts/password.py +14 -0
- PyInquirer/prompts/rawlist.py +183 -0
- PyInquirer/separator.py +15 -0
- PyInquirer/utils.py +34 -0
- examples/__init__.py +33 -0
- examples/checkbox.py +71 -0
- examples/confirm.py +32 -0
- examples/editor.py +28 -0
- examples/expand.py +46 -0
- examples/hierarchical.py +87 -0
- examples/input.py +47 -0
- examples/list.py +55 -0
- examples/password.py +21 -0
- examples/pizza.py +110 -0
- examples/rawlist.py +36 -0
- examples/when.py +46 -0
- pyinquirer-1.0.4.dist-info/METADATA +403 -0
- pyinquirer-1.0.4.dist-info/RECORD +32 -0
- pyinquirer-1.0.4.dist-info/WHEEL +6 -0
- pyinquirer-1.0.4.dist-info/licenses/LICENSE +19 -0
- pyinquirer-1.0.4.dist-info/top_level.txt +2 -0
examples/pizza.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
* Pizza delivery prompt example
|
|
4
|
+
* run example by writing `python example/pizza.py` in your console
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import print_function, unicode_literals
|
|
7
|
+
|
|
8
|
+
import re
|
|
9
|
+
from pprint import pprint
|
|
10
|
+
|
|
11
|
+
from PyInquirer import style_from_dict, Token, prompt
|
|
12
|
+
from PyInquirer import Validator, ValidationError
|
|
13
|
+
|
|
14
|
+
from examples import custom_style_3
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PhoneNumberValidator(Validator):
|
|
18
|
+
def validate(self, document):
|
|
19
|
+
ok = re.match(r'^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$', document.text)
|
|
20
|
+
if not ok:
|
|
21
|
+
raise ValidationError(
|
|
22
|
+
message='Please enter a valid phone number',
|
|
23
|
+
cursor_position=len(document.text)) # Move cursor to end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class NumberValidator(Validator):
|
|
27
|
+
def validate(self, document):
|
|
28
|
+
try:
|
|
29
|
+
int(document.text)
|
|
30
|
+
except ValueError:
|
|
31
|
+
raise ValidationError(
|
|
32
|
+
message='Please enter a number',
|
|
33
|
+
cursor_position=len(document.text)) # Move cursor to end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
print('Hi, welcome to Python Pizza')
|
|
37
|
+
|
|
38
|
+
questions = [
|
|
39
|
+
{
|
|
40
|
+
'type': 'confirm',
|
|
41
|
+
'name': 'toBeDelivered',
|
|
42
|
+
'message': 'Is this for delivery?',
|
|
43
|
+
'default': False
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
'type': 'input',
|
|
47
|
+
'name': 'phone',
|
|
48
|
+
'message': 'What\'s your phone number?',
|
|
49
|
+
'validate': PhoneNumberValidator
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
'type': 'list',
|
|
53
|
+
'name': 'size',
|
|
54
|
+
'message': 'What size do you need?',
|
|
55
|
+
'choices': ['Large', 'Medium', 'Small'],
|
|
56
|
+
'filter': lambda val: val.lower()
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
'type': 'input',
|
|
60
|
+
'name': 'quantity',
|
|
61
|
+
'message': 'How many do you need?',
|
|
62
|
+
'validate': NumberValidator,
|
|
63
|
+
'filter': lambda val: int(val)
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
'type': 'expand',
|
|
67
|
+
'name': 'toppings',
|
|
68
|
+
'message': 'What about the toppings?',
|
|
69
|
+
'choices': [
|
|
70
|
+
{
|
|
71
|
+
'key': 'p',
|
|
72
|
+
'name': 'Pepperoni and cheese',
|
|
73
|
+
'value': 'PepperoniCheese'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
'key': 'a',
|
|
77
|
+
'name': 'All dressed',
|
|
78
|
+
'value': 'alldressed'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
'key': 'w',
|
|
82
|
+
'name': 'Hawaiian',
|
|
83
|
+
'value': 'hawaiian'
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
'type': 'rawlist',
|
|
89
|
+
'name': 'beverage',
|
|
90
|
+
'message': 'You also get a free 2L beverage',
|
|
91
|
+
'choices': ['Pepsi', '7up', 'Coke']
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
'type': 'input',
|
|
95
|
+
'name': 'comments',
|
|
96
|
+
'message': 'Any comments on your purchase experience?',
|
|
97
|
+
'default': 'Nope, all good!'
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
'type': 'list',
|
|
101
|
+
'name': 'prize',
|
|
102
|
+
'message': 'For leaving a comment, you get a freebie',
|
|
103
|
+
'choices': ['cake', 'fries'],
|
|
104
|
+
'when': lambda answers: answers['comments'] != 'Nope, all good!'
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
answers = prompt(questions, style=custom_style_3)
|
|
109
|
+
print('Order receipt:')
|
|
110
|
+
pprint(answers)
|
examples/rawlist.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
* example for rawlist question type
|
|
4
|
+
* run example by typing `python example/checkbox.py` in your console
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import print_function, unicode_literals
|
|
7
|
+
|
|
8
|
+
from PyInquirer import style_from_dict, Token, prompt, print_json, Separator
|
|
9
|
+
|
|
10
|
+
from examples import custom_style_2
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
questions = [
|
|
14
|
+
{
|
|
15
|
+
'type': 'rawlist',
|
|
16
|
+
'name': 'theme',
|
|
17
|
+
'message': 'What do you want to do?',
|
|
18
|
+
'choices': [
|
|
19
|
+
'Order a pizza',
|
|
20
|
+
'Make a reservation',
|
|
21
|
+
Separator(),
|
|
22
|
+
'Ask opening hours',
|
|
23
|
+
'Talk to the receptionist'
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
'type': 'rawlist',
|
|
28
|
+
'name': 'size',
|
|
29
|
+
'message': 'What size do you need',
|
|
30
|
+
'choices': ['Jumbo', 'Large', 'Standard', 'Medium', 'Small', 'Micro'],
|
|
31
|
+
'filter': lambda val: val.lower()
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
answers = prompt(questions, style=custom_style_2)
|
|
36
|
+
print_json(answers)
|
examples/when.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
When example
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import print_function, unicode_literals
|
|
6
|
+
|
|
7
|
+
from PyInquirer import style_from_dict, Token, prompt, print_json
|
|
8
|
+
|
|
9
|
+
from examples import custom_style_2
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def dislikes_bacon(answers):
|
|
13
|
+
# demonstrate use of a function... here a lambda function would be enough
|
|
14
|
+
return not answers['bacon']
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
questions = [
|
|
18
|
+
{
|
|
19
|
+
'type': 'confirm',
|
|
20
|
+
'name': 'bacon',
|
|
21
|
+
'message': 'Do you like bacon?'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
'type': 'input',
|
|
25
|
+
'name': 'favorite',
|
|
26
|
+
'message': 'Bacon lover, what is your favorite type of bacon?',
|
|
27
|
+
'when': lambda answers: answers['bacon']
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
'type': 'confirm',
|
|
31
|
+
'name': 'pizza',
|
|
32
|
+
'message': 'Ok... Do you like pizza?',
|
|
33
|
+
'default': False, # only for demo :)
|
|
34
|
+
'when': dislikes_bacon
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
'type': 'input',
|
|
38
|
+
'name': 'favorite',
|
|
39
|
+
'message': 'Whew! What is your favorite type of pizza?',
|
|
40
|
+
'when': lambda answers: answers.get('pizza', False)
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
answers = prompt(questions, style=custom_style_2)
|
|
45
|
+
|
|
46
|
+
print_json(answers)
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PyInquirer
|
|
3
|
+
Version: 1.0.4
|
|
4
|
+
Summary: A Python module for collection of common interactive command line user interfaces, based on Inquirer.js
|
|
5
|
+
Home-page: https://github.com/CITGuru/PyInquirer/
|
|
6
|
+
Download-URL: https://github.com/CITGuru/PyInquirer/archive/1.0.4.tar.gz
|
|
7
|
+
Author: Oyetoke Toby
|
|
8
|
+
Author-email: oyetoketoby80@gmail.com
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: click,prompt-toolkit,cli,command-line,commandline,command-line-interface,python-inquiry,inquirer
|
|
11
|
+
Classifier: Development Status :: 1 - Planning
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Programming Language :: Python :: 2.7
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
21
|
+
Description-Content-Type: text/x-rst
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: prompt_toolkit<2.0,>=1.0.18
|
|
24
|
+
Requires-Dist: Pygments>=2.2.0
|
|
25
|
+
Dynamic: author
|
|
26
|
+
Dynamic: author-email
|
|
27
|
+
Dynamic: classifier
|
|
28
|
+
Dynamic: description
|
|
29
|
+
Dynamic: description-content-type
|
|
30
|
+
Dynamic: download-url
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: keywords
|
|
33
|
+
Dynamic: license
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
Dynamic: requires-dist
|
|
36
|
+
Dynamic: summary
|
|
37
|
+
|
|
38
|
+
PyInquirer
|
|
39
|
+
==========
|
|
40
|
+
|
|
41
|
+
PyInquirer is a collection of common interactive command line prompts for
|
|
42
|
+
Python, based on `Inquirer.js <https://github.com/SBoudrias/Inquirer.js>`__:
|
|
43
|
+
lists, checkboxes, confirmations, text and password input, and more.
|
|
44
|
+
|
|
45
|
+
Table of Contents
|
|
46
|
+
-----------------
|
|
47
|
+
|
|
48
|
+
1. `Documentation <#documentation>`__
|
|
49
|
+
|
|
50
|
+
1. `Installation <#installation>`__
|
|
51
|
+
2. `Examples <#examples>`__
|
|
52
|
+
3. `Quickstart <#quickstart>`__
|
|
53
|
+
4. `Question Types <#types>`__
|
|
54
|
+
5. `Question Properties <#properties>`__
|
|
55
|
+
6. `Prompt Options <#prompt-options>`__
|
|
56
|
+
7. `User Interfaces and Styles <#styles>`__
|
|
57
|
+
|
|
58
|
+
2. `Windows Platform <#windows>`__
|
|
59
|
+
3. `Support <#support>`__
|
|
60
|
+
4. `Contribution <#contribution>`__
|
|
61
|
+
5. `License <#license>`__
|
|
62
|
+
|
|
63
|
+
Goal and Philosophy
|
|
64
|
+
-------------------
|
|
65
|
+
|
|
66
|
+
**PyInquirer** strives to be an easily embeddable and beautiful
|
|
67
|
+
command line interface for `Python <https://python.org/>`__.
|
|
68
|
+
**PyInquirer** wants to make it easy for existing Inquirer.js users
|
|
69
|
+
to write immersive command line applications in Python. We are convinced
|
|
70
|
+
that its feature-set is the most complete for building immersive CLI
|
|
71
|
+
applications. We also hope that **PyInquirer** proves itself useful
|
|
72
|
+
to Python users.
|
|
73
|
+
|
|
74
|
+
**PyInquirer** should ease the process of
|
|
75
|
+
|
|
76
|
+
- providing *error feedback*
|
|
77
|
+
- *asking questions*
|
|
78
|
+
- *parsing* input
|
|
79
|
+
- *validating* answers
|
|
80
|
+
- managing *hierarchical prompts*
|
|
81
|
+
|
|
82
|
+
**Note:** **PyInquirer** provides the user interface and the inquiry
|
|
83
|
+
session flow.
|
|
84
|
+
|
|
85
|
+
Documentation
|
|
86
|
+
-------------
|
|
87
|
+
|
|
88
|
+
Installation
|
|
89
|
+
~~~~~~~~~~~~
|
|
90
|
+
|
|
91
|
+
Like most Python packages PyInquirer is available on `PyPI <https://pypi.org/project/PyInquirer/>`__.
|
|
92
|
+
Simply use pip to install the PyInquirer package
|
|
93
|
+
|
|
94
|
+
.. code:: shell
|
|
95
|
+
|
|
96
|
+
pip install PyInquirer
|
|
97
|
+
|
|
98
|
+
PyInquirer 1.0.x requires prompt\_toolkit 1.0.18, which is installed automatically.
|
|
99
|
+
|
|
100
|
+
Quickstart
|
|
101
|
+
~~~~~~~~~~
|
|
102
|
+
|
|
103
|
+
Like Inquirer.js, using inquirer is structured into two simple steps:
|
|
104
|
+
|
|
105
|
+
- you define a **list of questions** and hand them to **prompt**
|
|
106
|
+
- prompt returns a **dictionary of answers**
|
|
107
|
+
|
|
108
|
+
.. code:: python
|
|
109
|
+
|
|
110
|
+
from __future__ import print_function, unicode_literals
|
|
111
|
+
from PyInquirer import prompt, print_json
|
|
112
|
+
|
|
113
|
+
questions = [
|
|
114
|
+
{
|
|
115
|
+
'type': 'input',
|
|
116
|
+
'name': 'first_name',
|
|
117
|
+
'message': 'What\'s your first name',
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
answers = prompt(questions)
|
|
122
|
+
print_json(answers) # use the answers as input for your app
|
|
123
|
+
|
|
124
|
+
A good starting point from here is probably the examples section.
|
|
125
|
+
|
|
126
|
+
Examples
|
|
127
|
+
~~~~~~~~
|
|
128
|
+
|
|
129
|
+
Most of the examples intend to demonstrate a single question type or
|
|
130
|
+
feature:
|
|
131
|
+
|
|
132
|
+
- `editor.py <./examples/editor.py>`_
|
|
133
|
+
- `expand.py <./examples/expand.py>`_
|
|
134
|
+
- `list.py <./examples/list.py>`_
|
|
135
|
+
- `password.py <./examples/password.py>`_
|
|
136
|
+
- `when.py <./examples/when.py>`_
|
|
137
|
+
- `checkbox.py <./examples/checkbox.py>`_
|
|
138
|
+
- `confirm.py <./examples/confirm.py>`_
|
|
139
|
+
- `hierarchical.py <./examples/hierarchical.py>`_
|
|
140
|
+
- `pizza.py <./examples/pizza.py>`_ - demonstrate using different question types
|
|
141
|
+
- `editor.py <./examples/editor.py>`_
|
|
142
|
+
- `input.py <./examples/input.py>`_
|
|
143
|
+
- `rawlist.py <./examples/rawlist.py>`_
|
|
144
|
+
|
|
145
|
+
If you want to launch examples with the code from repository instead of
|
|
146
|
+
installing a package you need to execute ``pip install -e .`` within project
|
|
147
|
+
directory.
|
|
148
|
+
|
|
149
|
+
Question Types
|
|
150
|
+
~~~~~~~~~~~~~~
|
|
151
|
+
|
|
152
|
+
``questions`` is a list of questions. Each question has a type.
|
|
153
|
+
|
|
154
|
+
List - ``{type: 'list'}``
|
|
155
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
156
|
+
|
|
157
|
+
Take ``type``, ``name``, ``message``, ``choices``\ [, ``default``,
|
|
158
|
+
``filter``] properties. (Note that default must be the ``value``,
|
|
159
|
+
``name`` or ``index`` of a choice)
|
|
160
|
+
|
|
161
|
+
--------------
|
|
162
|
+
|
|
163
|
+
Raw List - ``{type: 'rawlist'}``
|
|
164
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
165
|
+
|
|
166
|
+
Take ``type``, ``name``, ``message``, ``choices``\ [, ``default``,
|
|
167
|
+
``filter``] properties. (Note that default must be the ``value`` or
|
|
168
|
+
``index`` of a choice)
|
|
169
|
+
|
|
170
|
+
.. figure:: https://raw.githubusercontent.com/citguru/PyInquirer/master/docs/images/raw-list.png
|
|
171
|
+
:alt: Raw list prompt
|
|
172
|
+
|
|
173
|
+
Raw list prompt
|
|
174
|
+
|
|
175
|
+
--------------
|
|
176
|
+
|
|
177
|
+
Expand - ``{type: 'expand'}``
|
|
178
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
179
|
+
|
|
180
|
+
Take ``type``, ``name``, ``message``, ``choices``\ [, ``default``]
|
|
181
|
+
properties. (Note that default must be the ``key`` of a choice. If
|
|
182
|
+
``default`` is not provided, the first choice is selected)
|
|
183
|
+
|
|
184
|
+
Note that the ``choices`` object will take an extra parameter called
|
|
185
|
+
``key`` for the ``expand`` prompt. This parameter must be a single
|
|
186
|
+
(lowercased) character. The ``h`` option is added by the prompt and
|
|
187
|
+
shouldn't be defined by the user.
|
|
188
|
+
|
|
189
|
+
See ``examples/expand.py`` for a running example.
|
|
190
|
+
|
|
191
|
+
|Expand prompt closed| |Expand prompt expanded|
|
|
192
|
+
|
|
193
|
+
--------------
|
|
194
|
+
|
|
195
|
+
Checkbox - ``{type: 'checkbox'}``
|
|
196
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
197
|
+
|
|
198
|
+
Take ``type``, ``name``, ``message``, ``choices``\ [, ``filter``,
|
|
199
|
+
``validate``] properties.
|
|
200
|
+
|
|
201
|
+
Choices marked as ``{checked: true}`` will be checked by default.
|
|
202
|
+
|
|
203
|
+
Choices whose property ``disabled`` is truthy will be unselectable. If
|
|
204
|
+
``disabled`` is a string, then the string will be outputted next to the
|
|
205
|
+
disabled choice.
|
|
206
|
+
|
|
207
|
+
.. figure:: https://raw.githubusercontent.com/citguru/PyInquirer/master/docs/images/checkbox-prompt.png
|
|
208
|
+
:alt: Checkbox prompt
|
|
209
|
+
|
|
210
|
+
Checkbox prompt
|
|
211
|
+
|
|
212
|
+
--------------
|
|
213
|
+
|
|
214
|
+
Confirm - ``{type: 'confirm'}``
|
|
215
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
216
|
+
|
|
217
|
+
Take ``type``, ``name``, ``message``\ [, ``default``] properties.
|
|
218
|
+
``default`` is expected to be a boolean if used.
|
|
219
|
+
|
|
220
|
+
.. figure:: https://raw.githubusercontent.com/citguru/PyInquirer/master/docs/images/confirm-prompt.png
|
|
221
|
+
:alt: Confirm prompt
|
|
222
|
+
|
|
223
|
+
Confirm prompt
|
|
224
|
+
|
|
225
|
+
--------------
|
|
226
|
+
|
|
227
|
+
Input - ``{type: 'input'}``
|
|
228
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
229
|
+
|
|
230
|
+
Take ``type``, ``name``, ``message``\ [, ``default``, ``filter``,
|
|
231
|
+
``validate``] properties.
|
|
232
|
+
|
|
233
|
+
.. figure:: https://raw.githubusercontent.com/citguru/PyInquirer/master/docs/images/input-prompt.png
|
|
234
|
+
:alt: Input prompt
|
|
235
|
+
|
|
236
|
+
Input prompt
|
|
237
|
+
|
|
238
|
+
--------------
|
|
239
|
+
|
|
240
|
+
Password - ``{type: 'password'}``
|
|
241
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
242
|
+
|
|
243
|
+
Take ``type``, ``name``, ``message``\ [, ``default``, ``filter``,
|
|
244
|
+
``validate``] properties.
|
|
245
|
+
|
|
246
|
+
.. figure:: https://raw.githubusercontent.com/citguru/PyInquirer/master/docs/images/password-prompt.png
|
|
247
|
+
:alt: Password prompt
|
|
248
|
+
|
|
249
|
+
Password prompt
|
|
250
|
+
|
|
251
|
+
--------------
|
|
252
|
+
|
|
253
|
+
Editor - ``{type: 'editor'}``
|
|
254
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
255
|
+
|
|
256
|
+
Take ``type``, ``name``, ``message``\ [, ``default``, ``filter``,
|
|
257
|
+
``validate``, ``eargs``] properties
|
|
258
|
+
|
|
259
|
+
**Editor Arguments -** ``eargs``
|
|
260
|
+
|
|
261
|
+
Opens an empty or edits the default text in the defined editor. If an editor is given
|
|
262
|
+
(should be the full path to the executable but the regular operating
|
|
263
|
+
system search path is used for finding the executable) it overrides
|
|
264
|
+
the detected editor. Optionally, some environment variables can be
|
|
265
|
+
used. If the editor is closed without changes, ``None`` is returned. In
|
|
266
|
+
case a file is edited directly the return value is always ``None`` and
|
|
267
|
+
``save`` and ``ext`` are ignored.
|
|
268
|
+
|
|
269
|
+
Takes:
|
|
270
|
+
|
|
271
|
+
- editor: accepts ``default`` to get the default platform editor. But
|
|
272
|
+
you can also provide the path to an editor e.g ``vi``.
|
|
273
|
+
- ext: the extension to tell the editor about. This defaults to `.txt`
|
|
274
|
+
but changing this might change syntax highlighting e.g ".py"
|
|
275
|
+
- save: accepts ``True`` or ``False`` to determine to save a file.
|
|
276
|
+
- filename: accepts the path of a file you'd like to edit.
|
|
277
|
+
- env: accepts any given environment variables to pass to the editor
|
|
278
|
+
|
|
279
|
+
Launches an instance of the users preferred editor on a temporary file.
|
|
280
|
+
Once the user exits their editor, the contents of the temporary file are
|
|
281
|
+
read in as the result. The editor to use is determined by reading the
|
|
282
|
+
``VISUAL`` or ``EDITOR`` environment variables. If neither of those
|
|
283
|
+
are present, notepad (on Windows) or vim (Linux or Mac) is used.
|
|
284
|
+
|
|
285
|
+
Question Properties
|
|
286
|
+
~~~~~~~~~~~~~~~~~~~
|
|
287
|
+
|
|
288
|
+
A question is a dictionary containing question related values:
|
|
289
|
+
|
|
290
|
+
- ``type``: (String) Type of the prompt. Possible values:
|
|
291
|
+
input, confirm, list, rawlist, expand, checkbox, password, editor
|
|
292
|
+
- ``name``: (String) The name to use when storing the answer in the answers
|
|
293
|
+
hash.
|
|
294
|
+
- ``message``: (String\|Function) The question to print. If defined as a
|
|
295
|
+
function, the first parameter will be the current inquirer session
|
|
296
|
+
answers.
|
|
297
|
+
- ``default``: (String\|Number\|Array\|Function) Default value(s) to use if
|
|
298
|
+
nothing is entered, or a function that returns the default value(s).
|
|
299
|
+
If defined as a function, the first parameter will be the current
|
|
300
|
+
inquirer session answers.
|
|
301
|
+
- ``choices``: (Array\|Function) Choices array or a function returning a
|
|
302
|
+
choices array. If defined as a function, the first parameter will be
|
|
303
|
+
the current inquirer session answers. Array values can be simple
|
|
304
|
+
strings, or objects containing a name (to display in list) and a value
|
|
305
|
+
(to save in the answers hash) property. The choices array can also contain a
|
|
306
|
+
Separator.
|
|
307
|
+
- ``validate``: (Function) Receive the user input and should return true if
|
|
308
|
+
the value is valid, and an error message (String) otherwise. If false
|
|
309
|
+
is returned, a default error message is provided.
|
|
310
|
+
- ``filter``: (Function) Receive the user input and return the filtered
|
|
311
|
+
value to be used inside the program. The value returned will be added
|
|
312
|
+
to the Answers hash.
|
|
313
|
+
- ``when``: (Function, Boolean) Receive the current user answers hash and
|
|
314
|
+
should return true or false depending on whether or not this question
|
|
315
|
+
should be asked. The value can also be a simple boolean.
|
|
316
|
+
|
|
317
|
+
Prompt Options
|
|
318
|
+
~~~~~~~~~~~~~~
|
|
319
|
+
|
|
320
|
+
``prompt(questions, answers=None, **options)`` takes the answers of a previous
|
|
321
|
+
prompt and the following options:
|
|
322
|
+
|
|
323
|
+
- ``style``: the style to use.
|
|
324
|
+
- ``raise_keyboard_interrupt``: with ``True`` pressing Ctrl-C raises
|
|
325
|
+
``KeyboardInterrupt``. By default a message is printed and ``prompt``
|
|
326
|
+
returns an empty dictionary.
|
|
327
|
+
- ``keyboard_interrupt_msg``: the message for Ctrl-C. Defaults to
|
|
328
|
+
``Cancelled by user``.
|
|
329
|
+
|
|
330
|
+
User Interfaces and Styles
|
|
331
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
332
|
+
|
|
333
|
+
The colors are set by a style:
|
|
334
|
+
|
|
335
|
+
.. code:: python
|
|
336
|
+
|
|
337
|
+
from PyInquirer import prompt, style_from_dict, Token
|
|
338
|
+
|
|
339
|
+
style = style_from_dict({
|
|
340
|
+
Token.QuestionMark: '#E91E63 bold',
|
|
341
|
+
Token.Selected: '#673AB7 bold',
|
|
342
|
+
Token.Answer: '#2196f3 bold',
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
answers = prompt(questions, style=style)
|
|
346
|
+
|
|
347
|
+
Windows Platform
|
|
348
|
+
----------------
|
|
349
|
+
|
|
350
|
+
**``PyInquirer``** is build on prompt\_toolkit which is cross platform,
|
|
351
|
+
and everything that you build on top should run fine on both Unix and
|
|
352
|
+
Windows systems. On Windows, it uses a different event loop
|
|
353
|
+
(WaitForMultipleObjects instead of select), and another input and output
|
|
354
|
+
system. (Win32 APIs instead of pseudo-terminals and VT100.)
|
|
355
|
+
|
|
356
|
+
It's worth noting that the implementation is a "best effort of what is
|
|
357
|
+
possible". Both Unix and Windows terminals have their limitations. But
|
|
358
|
+
in general, the Unix experience will still be a little better.
|
|
359
|
+
|
|
360
|
+
For Windows, it's recommended to use either cmder or conemu.
|
|
361
|
+
|
|
362
|
+
Support
|
|
363
|
+
-------
|
|
364
|
+
|
|
365
|
+
Most of the questions are probably related to using a question type or
|
|
366
|
+
feature. Please lookup and study the appropriate examples.
|
|
367
|
+
|
|
368
|
+
You can also open an `issue on GitHub <https://github.com/CITGuru/PyInquirer/issues>`__.
|
|
369
|
+
|
|
370
|
+
For many issues like for example common Python programming issues
|
|
371
|
+
stackoverflow might be a good place to search for an answer.
|
|
372
|
+
|
|
373
|
+
Contribution
|
|
374
|
+
------------
|
|
375
|
+
|
|
376
|
+
.. code:: shell
|
|
377
|
+
|
|
378
|
+
$ git clone git@github.com:CITGuru/PyInquirer.git
|
|
379
|
+
$ cd PyInquirer
|
|
380
|
+
$ python -m venv venv
|
|
381
|
+
$ source venv/bin/activate
|
|
382
|
+
$ pip install --upgrade pip
|
|
383
|
+
$ pip install -r requirements.txt
|
|
384
|
+
$ pip install -r requirements_dev.txt
|
|
385
|
+
|
|
386
|
+
With an environment ready you can add new feature and check everything works
|
|
387
|
+
just fine
|
|
388
|
+
|
|
389
|
+
.. code:: shell
|
|
390
|
+
|
|
391
|
+
$ pytest -sv tests/
|
|
392
|
+
|
|
393
|
+
That's it, now you can fork a project and submit PR with your change!
|
|
394
|
+
|
|
395
|
+
License
|
|
396
|
+
-------
|
|
397
|
+
|
|
398
|
+
Copyright (c) 2018 Oyetoke Toby (twitter: @oyetokeT)
|
|
399
|
+
|
|
400
|
+
Licensed under the MIT license.
|
|
401
|
+
|
|
402
|
+
.. |Expand prompt closed| image:: https://raw.githubusercontent.com/citguru/PyInquirer/master/docs/images/expand-prompt-1.png
|
|
403
|
+
.. |Expand prompt expanded| image:: https://raw.githubusercontent.com/citguru/PyInquirer/master/docs/images/expand-prompt-2.png
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
PyInquirer/__init__.py,sha256=kagZGVcY7Qu1_2726uR7ZARyUUwE5zDdF-rBYxYJyGk,785
|
|
2
|
+
PyInquirer/color_print.py,sha256=x1hRyTZL5f_vdpX8ZVeGXvl9gHWb7KU7XydrnVck0iw,963
|
|
3
|
+
PyInquirer/prompt.py,sha256=gCMpeMe3GoLi_kztq7SOd3BMUa7pSI508mzoAu1GTrI,3960
|
|
4
|
+
PyInquirer/separator.py,sha256=H0vX4NQkdiOGjITuPE9recoJSXVsM63CCddPMVUTZlU,247
|
|
5
|
+
PyInquirer/utils.py,sha256=rXsFmpcUNJ-vmGR328b1C3KQZkCbJ2JOYpeRt0NE06E,903
|
|
6
|
+
PyInquirer/prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
PyInquirer/prompts/checkbox.py,sha256=iU48gTx17QcylO9hFTUoNmcaA1D4ztdat83dcptRd6g,9383
|
|
8
|
+
PyInquirer/prompts/common.py,sha256=SC1zvfgnfzQyk8hJbatNJZdpuALgLh6LWFR7omwwCB8,3067
|
|
9
|
+
PyInquirer/prompts/confirm.py,sha256=zw8cRqHSgbxGy3rFpFkgarPeTQJoMHJZc9cb9vRfG-o,2714
|
|
10
|
+
PyInquirer/prompts/editor.py,sha256=Bi6aVptUKgk_mlXBiStOHiqVQKa0Ad4GGN3jFm6uqa8,5889
|
|
11
|
+
PyInquirer/prompts/expand.py,sha256=Q39-VViufatO4J4ZSvXB3yh1ws4sVoqVcuzyCUqT8Hc,6539
|
|
12
|
+
PyInquirer/prompts/input.py,sha256=Vyh-rxI8Nk_O0fbQKd7EgNMPTlrGJOvKY6Xexm7lBzM,1906
|
|
13
|
+
PyInquirer/prompts/list.py,sha256=UbeJBFhFuYF29D7bi5tVZoWrBEnhJJLZ_0i1YeJ-DLU,7078
|
|
14
|
+
PyInquirer/prompts/password.py,sha256=2FIqHIHczneg-s2Eri_gX76ScQ0StwpZTjlOP5qnFWQ,282
|
|
15
|
+
PyInquirer/prompts/rawlist.py,sha256=2zoUCuSkExcKvt2nUHnuRdbhZtCyAPLP4ZoyUe_NNCY,6249
|
|
16
|
+
examples/__init__.py,sha256=Varm3SPOhf2zLZxg6Dgb4GIp5CGKzUFhaHOBVz5izQk,853
|
|
17
|
+
examples/checkbox.py,sha256=u2FpZikMITB5APjZfqkzHlJ8phS091tPNCp0Piq2Fdk,1688
|
|
18
|
+
examples/confirm.py,sha256=1YFDmAA22APcYbnnlwIY_ycPr_pBRQBg8_pysxwvrHw,619
|
|
19
|
+
examples/editor.py,sha256=kkiUzbKKSr_7CxjIjvz9SAZdO16H-mhyPit2ufJ9VDY,716
|
|
20
|
+
examples/expand.py,sha256=9tvublxdxVVnzW4SmHpHhx8sELSI2YfGE_aY0XODaWM,1139
|
|
21
|
+
examples/hierarchical.py,sha256=5AlzvAruFeN7R2652YlYDwK1IkUPU372iij9m5o5B3o,2369
|
|
22
|
+
examples/input.py,sha256=FtGCntkHqS_A65vQGPq1wcWs8iuz9EKGunUJiHumYFM,1387
|
|
23
|
+
examples/list.py,sha256=h3BLEN5tdH6ySBQ-KXoI7kKQ671vSKP7jO3JGVwNbtE,1320
|
|
24
|
+
examples/password.py,sha256=M3t0wSUC5ZZeCRenWxyyHnHyMQNn4KAj8-_fbEEHOr4,422
|
|
25
|
+
examples/pizza.py,sha256=CZxt_ZyYZ1HUOVd5HJWTngqhNGdfA6G_DxSd8fvGPUc,3019
|
|
26
|
+
examples/rawlist.py,sha256=oDv7svGqDtIA1LpJS8t61z99MnGW55gFsGZSo7kAQ5U,927
|
|
27
|
+
examples/when.py,sha256=duxARbzyRqeCiccXOyJ9-NLRf-w_EGYw3Be1Z-4sJ0s,1107
|
|
28
|
+
pyinquirer-1.0.4.dist-info/licenses/LICENSE,sha256=Cbm8zDhFWLjYrAc6oXFjJGvqnQmtc4zgJebeWkaTPHA,1069
|
|
29
|
+
pyinquirer-1.0.4.dist-info/METADATA,sha256=Amvri101zMZnzA4UxJKe9VFKSxxR4PCY7VpA7hEX2YM,13287
|
|
30
|
+
pyinquirer-1.0.4.dist-info/WHEEL,sha256=Uvlg2aNlEKdilsyFSJt1QX5me0eEbCjQzR3nZeFkvy4,109
|
|
31
|
+
pyinquirer-1.0.4.dist-info/top_level.txt,sha256=p245sE94uPc9V_xRFOOPd85XfL16EsM0CfQWOMU6tUc,20
|
|
32
|
+
pyinquirer-1.0.4.dist-info/RECORD,,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright 2018 Oyetoke Toby and contributors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
+
so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|