Skip to content

Commit 9623162

Browse files
committed
Initial Push
0 parents  commit 9623162

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3109
-0
lines changed

.bumpversion.cfg

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[bumpversion]
2+
current_version = 0.5.2
3+
4+
[bumpversion:file:setup.py]
5+
6+
[bumpversion:file:PyInquirer/__init__.py]
7+

.gitignore

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
*.egg-info
2+
.*.swp
3+
.*.swo
4+
*.pyc
5+
.DS_Store
6+
dist
7+
.tox
8+
.coverage
9+
htmlcov
10+
six-*.egg/
11+
*.orig
12+
.idea/
13+
*.iml
14+
*.log
15+
16+
bak
17+
output
18+
output_*
19+
research
20+
venv
21+
venv3
22+
cache
23+
.cache
24+
vendor
25+
xvendor
26+
node_modules
27+
28+
report.xml
29+
pylint-report.html
30+
pytest-report.html
31+
set_w
32+
snafu.py
33+
set_infra

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright 2016 Fink Labs GmbH and inquirerpy 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.

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include LICENSE README.md requirements.txt

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
#SPHINXPROJ =
8+
SOURCEDIR = docs
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

PyInquirer/__init__.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import absolute_import, print_function
4+
import os
5+
6+
from prompt_toolkit.token import Token
7+
from prompt_toolkit.styles import style_from_dict
8+
from prompt_toolkit.validation import Validator, ValidationError
9+
10+
from .utils import print_json, format_json
11+
12+
13+
__version__ = '0.5.2'
14+
15+
16+
def here(p):
17+
return os.path.abspath(os.path.join(os.path.dirname(__file__), p))
18+
19+
20+
class PromptParameterException(ValueError):
21+
def __init__(self, message, errors=None):
22+
23+
# Call the base class constructor with the parameters it needs
24+
super(PromptParameterException, self).__init__(
25+
'You must provide a `%s` value' % message, errors)
26+
27+
from .prompt import prompt
28+
from .separator import Separator
29+
from .prompts.common import default_style

PyInquirer/color_print.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
provide colorized output
4+
"""
5+
from __future__ import print_function, unicode_literals
6+
import sys
7+
from prompt_toolkit.shortcuts import print_tokens, style_from_dict, Token
8+
9+
10+
def _print_token_factory(col):
11+
"""Internal helper to provide color names."""
12+
def _helper(msg):
13+
style = style_from_dict({
14+
Token.Color: col,
15+
})
16+
tokens = [
17+
(Token.Color, msg)
18+
]
19+
print_tokens(tokens, style=style)
20+
21+
def _helper_no_terminal(msg):
22+
# workaround if we have no terminal
23+
print(msg)
24+
if sys.stdout.isatty():
25+
return _helper
26+
else:
27+
return _helper_no_terminal
28+
29+
# used this for color source:
30+
# http://unix.stackexchange.com/questions/105568/how-can-i-list-the-available-color-names
31+
yellow = _print_token_factory('#dfaf00')
32+
blue = _print_token_factory('#0087ff')
33+
gray = _print_token_factory('#6c6c6c')
34+
35+
# TODO
36+
#black
37+
#red
38+
#green
39+
#magenta
40+
#cyan
41+
#white

PyInquirer/prompt.py

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import absolute_import, print_function
4+
5+
from prompt_toolkit.shortcuts import run_application
6+
7+
from . import PromptParameterException, prompts
8+
from .prompts import list, confirm, input, password, checkbox, rawlist, expand
9+
10+
11+
def prompt(questions, answers=None, **kwargs):
12+
if isinstance(questions, dict):
13+
questions = [questions]
14+
answers = answers or {}
15+
16+
patch_stdout = kwargs.pop('patch_stdout', False)
17+
return_asyncio_coroutine = kwargs.pop('return_asyncio_coroutine', False)
18+
true_color = kwargs.pop('true_color', False)
19+
refresh_interval = kwargs.pop('refresh_interval', 0)
20+
eventloop = kwargs.pop('eventloop', None)
21+
22+
for question in questions:
23+
# import the question
24+
if not 'type' in question:
25+
raise PromptParameterException('type')
26+
if not 'name' in question:
27+
raise PromptParameterException('name')
28+
if not 'message' in question:
29+
raise PromptParameterException('message')
30+
try:
31+
_kwargs = {}
32+
_kwargs.update(kwargs)
33+
_kwargs.update(question)
34+
type = _kwargs.pop('type')
35+
name = _kwargs.pop('name')
36+
message = _kwargs.pop('message')
37+
when = _kwargs.pop('when', None)
38+
filter = _kwargs.pop('filter', None)
39+
if when:
40+
# at least a little sanity check!
41+
if callable(question['when']):
42+
try:
43+
if not question['when'](answers):
44+
continue
45+
except Exception as e:
46+
raise ValueError(
47+
'Problem in \'when\' check of %s question: %s' %
48+
(name, e))
49+
else:
50+
raise ValueError('\'when\' needs to be function that ' \
51+
'accepts a dict argument')
52+
if filter:
53+
# at least a little sanity check!
54+
if not callable(question['filter']):
55+
raise ValueError('\'filter\' needs to be function that ' \
56+
'accepts an argument')
57+
58+
if callable(question.get('default')):
59+
_kwargs['default'] = question['default'](answers)
60+
61+
application = getattr(prompts, type).question(message, **_kwargs)
62+
63+
answer = run_application(
64+
application,
65+
patch_stdout=patch_stdout,
66+
return_asyncio_coroutine=return_asyncio_coroutine,
67+
true_color=true_color,
68+
refresh_interval=refresh_interval,
69+
eventloop=eventloop)
70+
71+
if answer is not None:
72+
if filter:
73+
try:
74+
answer = question['filter'](answer)
75+
except Exception as e:
76+
raise ValueError(
77+
'Problem processing \'filter\' of %s question: %s' %
78+
(name, e))
79+
answers[name] = answer
80+
except AttributeError as e:
81+
print(e)
82+
raise ValueError('No question type \'%s\'' % type)
83+
except KeyboardInterrupt:
84+
print('')
85+
print('Cancelled by user')
86+
print('')
87+
return {}
88+
return answers
89+
90+
91+
# TODO:
92+
# Bottom Bar - inquirer.ui.BottomBar

PyInquirer/prompts/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)