Skip to content

Commit 99e018e

Browse files
committed
Fix broken prompts in upgrade
1 parent fcc46eb commit 99e018e

18 files changed

+55
-52
lines changed

PyInquirer/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44

55
from .utils import print_json, format_json
6-
from .prompt import prompt
6+
# from .prompt import prompt
77
from .separator import Separator
88
from .prompts.common import default_style
99

@@ -34,3 +34,5 @@ def style_from_dict(style_dict):
3434

3535
from pygments.token import Token
3636
from prompt_toolkit.validation import Validator, ValidationError
37+
38+
__all__ = ["PromptParameterException", "style_from_dict"]

PyInquirer/prompt.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,18 @@ def prompt(questions, answers=None, **kwargs):
6868
_kwargs['default'] = question['default'](answers)
6969

7070
with pt_patch_stdout() if patch_stdout else _dummy_context_manager():
71-
result = getattr(prompts, type).question(message, **_kwargs)
71+
result = getattr(prompts, type_).question(message, **_kwargs)
72+
7273

7374
if isinstance(result, PromptSession):
7475
answer = result.prompt()
7576
elif isinstance(result, Application):
7677
answer = result.run()
7778
else:
78-
assert isinstance(answer, str)
79+
# assert isinstance(answer, str)
7980
answer = result
8081

81-
#answer = application.run(
82+
# answer = application.run(
8283
# return_asyncio_coroutine=return_asyncio_coroutine,
8384
# true_color=true_color,
8485
# refresh_interval=refresh_interval)

PyInquirer/prompts/editor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def question(message, **kwargs):
140140
elif callable(validate_prompt):
141141
class _InputValidator(Validator):
142142
def validate(self, document):
143+
# print(document)
143144
verdict = validate_prompt(document.text)
144145
if not verdict == True:
145146
if verdict == False:
@@ -190,7 +191,8 @@ def _get_prompt_tokens():
190191
return PromptSession(
191192
message=_get_prompt_tokens,
192193
lexer=SimpleLexer('class:answer'),
193-
default=default,
194194
multiline=multiline,
195+
enable_open_in_editor=True,
196+
vi_mode=True,
195197
**kwargs
196198
)

PyInquirer/prompts/rawlist.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from prompt_toolkit.layout.containers import ConditionalContainer, HSplit
1111
from prompt_toolkit.layout.dimension import LayoutDimension as D
1212

13+
from prompt_toolkit.layout import Layout
14+
15+
1316
from . import PromptParameterException
1417
from ..separator import Separator
1518
from .common import default_style
@@ -145,7 +148,7 @@ def set_answer(event):
145148
event.app.exit(result=ic.get_selected_value())
146149

147150
return Application(
148-
layout=layout,
151+
layout=Layout(layout),
149152
key_bindings=kb,
150153
mouse_support=True,
151154
style=style

README.rst

-2
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,6 @@ __ Sponsor_
407407
License
408408
-------
409409

410-
Copyright (c) 2016-2017 Mark Fink (twitter: @markfink)
411-
412410
Copyright (c) 2018 Oyetoke Toby (twitter: @oyetokeT)
413411

414412
Licensed under the MIT license.

examples/__init__.py

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
from prompt_toolkit.styles import style_from_dict
2-
from prompt_toolkit.token import Token
3-
from prompt_toolkit.validation import Validator, ValidationError
1+
from PyInquirer import style_from_dict
42

53
custom_style_1 = style_from_dict({
6-
Token.Separator: '#cc5454',
7-
Token.QuestionMark: '#673ab7 bold',
8-
Token.Selected: '#cc5454', # default
9-
Token.Pointer: '#673ab7 bold',
10-
Token.Instruction: '', # default
11-
Token.Answer: '#f44336 bold',
12-
Token.Question: '',
4+
"separator": '#cc5454',
5+
"questionmark": '#673ab7 bold',
6+
"selected": '#cc5454', # default
7+
"pointer": '#673ab7 bold',
8+
"instruction": '', # default
9+
"answer": '#f44336 bold',
10+
"question": '',
1311
})
1412

1513

1614
custom_style_2 = style_from_dict({
17-
Token.Separator: '#6C6C6C',
18-
Token.QuestionMark: '#FF9D00 bold',
19-
#Token.Selected: '', # default
20-
Token.Selected: '#5F819D',
21-
Token.Pointer: '#FF9D00 bold',
22-
Token.Instruction: '', # default
23-
Token.Answer: '#5F819D bold',
24-
Token.Question: '',
15+
"separator": '#6C6C6C',
16+
"questionmark": '#FF9D00 bold',
17+
"selected": '#5F819D',
18+
"pointer": '#FF9D00 bold',
19+
"instruction": '', # default
20+
"answer": '#5F819D bold',
21+
"question": '',
2522
})
2623

2724

2825
custom_style_3 = style_from_dict({
29-
Token.QuestionMark: '#E91E63 bold',
30-
Token.Selected: '#673AB7 bold',
31-
Token.Instruction: '', # default
32-
Token.Answer: '#2196f3 bold',
33-
Token.Question: '',
26+
"questionmark": '#E91E63 bold',
27+
"selected": '#673AB7 bold',
28+
"instruction": '', # default
29+
"answer": '#2196f3 bold',
30+
"question": '',
3431
})

examples/checkbox.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@
6565
}
6666
]
6767

68-
answers = prompt(questions, style=custom_style_2)
68+
answers = prompt.prompt(questions, style=custom_style_2)
6969
pprint(answers)

examples/confirm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
},
2626
]
2727

28-
answers = prompt(questions, style=custom_style_1)
28+
answers = prompt.prompt(questions, style=custom_style_1)
2929
pprint(answers)
3030

examples/editor.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
'name': 'bio',
1515
'message': 'Please write a short bio of at least 3 lines.',
1616
'default': 'Hello World',
17-
'validate': lambda text: len(text.split('\n')) >= 3 or 'Must be at least 3 lines.',
17+
'validate': lambda text: len(text.split('\n')) >= 1 or 'Must be at least 3 lines.',
1818
'eargs': {
19-
'editor':'default',
19+
'editor':'nano',
2020
'ext':'.py'
2121
}
2222
}
2323
]
2424

25-
answers = prompt(questions, style=custom_style_2)
25+
answers = prompt.prompt(questions, style=custom_style_2)
2626
pprint(answers)

examples/expand.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@
4141
}
4242
]
4343

44-
answers = prompt(questions, style=custom_style_2)
44+
answers = prompt.prompt(questions, style=custom_style_2)
4545
print_json(answers)

examples/hierarchical.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
hierarchical prompt usage example
44
"""
5-
from PyInquirer import style_from_dict, Token, prompt
5+
from PyInquirer import style_from_dict, prompt
66

77
from examples import custom_style_2
88

@@ -14,7 +14,7 @@ def ask_direction():
1414
'message': 'Which direction would you like to go?',
1515
'choices': ['Forward', 'Right', 'Left', 'Back']
1616
}
17-
answers = prompt(directions_prompt)
17+
answers = prompt.prompt(directions_prompt)
1818
return answers['direction']
1919

2020
# TODO better to use while loop than recursion!
@@ -67,7 +67,7 @@ def encounter2a():
6767

6868

6969
def encounter2b():
70-
prompt({
70+
prompt.prompt({
7171
'type': 'list',
7272
'name': 'weapon',
7373
'message': 'Pick one',

examples/input.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ def validate(self, document):
4444
}
4545
]
4646

47-
answers = prompt(questions, style=custom_style_2)
47+
answers = prompt.prompt(questions, style=custom_style_2)
4848
pprint(answers)

examples/list.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ def get_delivery_options(answers):
5151
},
5252
]
5353

54-
answers = prompt(questions, style=custom_style_2)
54+
answers = prompt.prompt(questions, style=custom_style_2)
5555
pprint(answers)

examples/password.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
}
1818
]
1919

20-
answers = prompt(questions, style=custom_style_2)
20+
answers = prompt.prompt(questions, style=custom_style_2)
2121
print_json(answers)

examples/pizza.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ def validate(self, document):
106106
}
107107
]
108108

109-
answers = prompt(questions, style=custom_style_3)
109+
answers = prompt.prompt(questions, style=custom_style_3)
110110
print('Order receipt:')
111111
pprint(answers)

examples/rawlist.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
}
3333
]
3434

35-
answers = prompt(questions, style=custom_style_2)
35+
answers = prompt.prompt(questions, style=custom_style_2)
3636
print_json(answers)

examples/when.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def dislikes_bacon(answers):
4141
}
4242
]
4343

44-
answers = prompt(questions, style=custom_style_2)
44+
answers = prompt.prompt(questions, style=custom_style_2)
4545

4646
print_json(answers)

tests/helpers.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from prompt_toolkit.shortcuts.prompt import PromptSession
2121

2222

23-
from PyInquirer import prompts
23+
from PyInquirer import prompts, style_from_dict
2424

2525

2626
# http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/?in=user-97991
@@ -45,11 +45,11 @@ def __init__(self, **kwds):
4545

4646

4747
style = style_from_dict({
48-
Token.QuestionMark: '#FF9D00 bold',
49-
Token.Selected: '#5F819D bold',
50-
Token.Instruction: '', # default
51-
Token.Answer: '#5F819D bold',
52-
Token.Question: '',
48+
"questionmark": '#FF9D00 bold',
49+
"selected": '#5F819D bold',
50+
"instruction": '', # default
51+
"answer": '#5F819D bold',
52+
"question": '',
5353
})
5454

5555

0 commit comments

Comments
 (0)