Skip to content

Commit

Permalink
🚀🚀🎭
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum-quirks committed Mar 6, 2022
1 parent 5e77d77 commit 1a2a2ec
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 51 deletions.
22 changes: 14 additions & 8 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ Changelog
``Version 2022.3``
--------------------

Unreleased
Released on 2022-3-6

**Added**
^^^^^^^^^^
- Added :kbd:`<any>` enabling the user to press any key to exit the help page.
- Introduced :class:`quo.keys.Bind` as an alias of :class:`quo.keys.KeyBinder`

**Changed**
^^^^^^^^^^^^
- Changed :param:`enable_system_elicit` in favor of :param:`system_prompt`.
- Changed :param:`enable_suspend` in favor of :param:`suspend`.

**Fixed**
^^^^^^^^^
- Optimized the help parameter.
- Deprecated notice `TypeError`
^^^^^^^^^^
- Optimized the help page.
- Fixed Deprecated notice `TypeError`

**Added**
----------
Introduced :class:`quo.keys.Bind` as an alias of :class:`quo.keys.KeyBinder`
Added :kbd:`<any>` enabling the user to press any key to exit the help page

``Version 2022.2.2``
--------------------
Expand Down
26 changes: 26 additions & 0 deletions docs/prompt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,32 @@ as a boolean value:
confirm('Do you want to continue?')
``System prompt``
------------------
If you press :kbd:`meta-!` or :kbd:`esc-!`, you can enter system commands like `ls` or `cd`.

.. code:: python
from quo.prompt import Prompt
session = Prompt(system_prompt=True)
session.prompt("Give me some input: ")
``Suspend prompt``
-------------------
Pressing :kbd:`ctrl-z` will suspend the process from running and then run the command `fg` to continue the process.

.. code:: python
from quo.prompt import Prompt
session = Prompt(suspend=True)
sessiom.prompr("Give me some input: ")
``Prompt bottom toolbar``
---------------------------
Adding a bottom toolbar is as easy as passing a bottom_toolbar argument to prompt(). This argument be either plain text, formatted text or a callable that returns plain or formatted text.
Expand Down
26 changes: 14 additions & 12 deletions examples/prompts/system-prompt.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#!/usr/bin/env python

import quo
from quo import echo
from quo.console import app, command
from quo.prompt import Prompt

session = quo.Prompt()
session = Prompt()

@quo.command()
@quo.app("@prompt")
@command()
@app("--prompt")
def main(prompt):
quo.echo("(1/3) If you press meta-! or esc-! at the following prompt, you can enter system commands.")
echo("(1/3) If you press meta-! or esc-! at the following prompt, you can enter system commands.")

answer = session.prompt("Give me some input: ", enable_system_elicit=True)
quo.echo(f"You said: {answer}")
answer = session.prompt("Give me some input: ", system_prompt=True)
echo(f"You said: {answer}")

# Enable suspend.
quo.echo("(2/3) If you press Control-Z, the application will suspend.")
answer = session.prompt("Give me some input: ", enable_suspend=True)
quo.echo(f"You said: {answer}")
echo("(2/3) If you press Control-Z, the application will suspend.")
answer = session.prompt("Give me some input: ", suspend=True)
echo(f"You said: {answer}")

# Enable open_in_editor
quo.echo("(3/3) If you press Control-X Control-E, the prompt will open in $EDITOR.")
echo("(3/3) If you press Control-X Control-E, the prompt will open in $EDITOR.")
answer = session.prompt("Give me some input: ", enable_open_in_editor=True)
quo.echo(f"You said: {answer}")
echo(f"You said: {answer}")

if __name__ == "__main__":
main()
4 changes: 1 addition & 3 deletions src/quo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@
BufferControl(buffer=buff),
left_margins=[NumberedMargin(), ScrollbarMargin()],
right_margins=[ScrollbarMargin(), ScrollbarMargin()],),
VSplit([
Label("djdjd")]),
]),


]),
])
root1 = Label(
Text('<style fg="aquamarine" bg="purple"> Press Ctrl-L to launch the documentation</style>'))
Expand Down
58 changes: 30 additions & 28 deletions src/quo/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ class CompleteStyle(str, Enum):
##

def prompt(
text,
default=None,
text: str,
default: str = None,
hide=False,
affirm=False,
type=None,
value_proc=None,
suffix=":> ",
suffix: str = ":> ",
show_default=True,
err=False,
show_choices=True,
Expand All @@ -241,7 +241,8 @@ def prompt(
:param show_default: shows or hides the default value in the prompt.
:param err: if set to true the file defaults to ``stderr`` instead of ``stdout``, the same as with echo.
:param show_choices: Show or hide choices if the passed type is a Choice. For example if type is a Choice of either day or week, show_choices is true and text is "Group by" then the prompt will be "Group by (day, week): ".
Example usage:: s = prompt("")
Example usage::
s = prompt("")
"""
Expand Down Expand Up @@ -331,7 +332,7 @@ class Prompt(Generic[_T]):
:param wrap_lines: `bool` or :class:`~quo.filters.Filter`.
When True (the default), automatically wrap long lines instead of
scrolling horizontally.
:param is_password: Show asterisks instead of the actual typed characters.
:param hide: Show asterisks instead of the actual typed characters.
:param editing_mode: ``EditingMode.VI`` or ``EditingMode.EMACS``.
:param vi_mode: `bool`, if True, Identical to ``editing_mode=EditingMode.VI``.
:param complete_while_typing: `bool` or
Expand All @@ -345,9 +346,9 @@ class Prompt(Generic[_T]):
string matching.
:param search_ignore_case:
:class:`~quo.filters.Filter`. Search case insensitive.
:param lexer: :class:`~quo.lexers.Lexer` to be used for the
:param highlighter: :class:`~quo.lexers.Lexer` to be used for the
syntax highlighting.
:param validator: :class:`~quo.types.Validator` instance
:param type: :class:`~quo.types.Validator` instance
for input validation.
:param completer: :class:`~quo.completion.Completer` instance
for input completion.
Expand All @@ -374,7 +375,7 @@ class Prompt(Generic[_T]):
:class:`~quo.style.SwapLightAndDarkStyleTransformation`.
This is useful for switching between dark and light terminal
backgrounds.
:param enable_system_elicit: `bool` or
:param system_prompt: `bool` or
:class:`~quo.filters.Filter`. Pressing Meta+'!' will show
a system elicit.
:param enable_suspend: `bool` or :class:`~quo.filters.Filter`.
Expand Down Expand Up @@ -411,7 +412,7 @@ class Prompt(Generic[_T]):

_fields = (
"text",
"lexer",
"highlighter",
"completer",
"complete_in_thread",
"is_password",
Expand All @@ -431,6 +432,7 @@ class Prompt(Generic[_T]):
"wrap_lines",
"enable_history_search",
"search_ignore_case",
"dynamic_completion",
"complete_while_typing",
"validate_while_typing",
"complete_style",
Expand Down Expand Up @@ -464,8 +466,8 @@ def __init__(
enable_history_search: FilterOrBool = True, #False,
search_ignore_case: FilterOrBool = False,
highlighter: Optional[Lexer] = None,
enable_system_elicit: FilterOrBool = False,
enable_suspend: FilterOrBool = False,
system_prompt: FilterOrBool = False,
suspend: FilterOrBool = False,
enable_open_in_editor: FilterOrBool = False,
type: Optional[Validator] = None,
completer: Optional[Completer] = None,
Expand Down Expand Up @@ -536,8 +538,8 @@ def __init__(
self.refresh_interval = refresh_interval
self.input_processors = input_processors
self.placeholder = placeholder
self.enable_system_elicit = enable_system_elicit
self.enable_suspend = enable_suspend
self.system_prompt = system_prompt
self.suspend = suspend
self.enable_open_in_editor = enable_open_in_editor
self.reserve_space_for_menu = reserve_space_for_menu
self.tempfile_suffix = tempfile_suffix
Expand Down Expand Up @@ -672,7 +674,7 @@ def display_placeholder() -> bool:
)

system_toolbar = SystemToolbar(
enable_global_bindings=dyncond("enable_system_elicit")
enable_global_bindings=dyncond("system_prompt")
)

def get_search_buffer_control() -> SearchBufferControl:
Expand Down Expand Up @@ -771,7 +773,7 @@ def multi_column_complete_style() -> bool:
),
ConditionalContainer(ValidationToolbar(), filter=~is_done),
ConditionalContainer(
system_toolbar, dyncond("enable_system_elicit") & ~is_done
system_toolbar, dyncond("system_prompt") & ~is_done
),
# In multiline mode, we use two toolbars for 'arg' and 'search'.
ConditionalContainer(
Expand Down Expand Up @@ -913,7 +915,7 @@ def _eof(event: E) -> None:

@Condition
def enable_suspend() -> bool:
return to_filter(self.enable_suspend)()
return to_filter(self.suspend)()

@handle("ctrl-z", filter=suspend_supported & enable_suspend)
def _suspend(event: E) -> None:
Expand Down Expand Up @@ -959,8 +961,8 @@ def prompt(
input_processors: Optional[List[Processor]] = None,
placeholder: Optional[AnyFormattedText] = None,
reserve_space_for_menu: Optional[int] = None,
enable_system_elicit: Optional[FilterOrBool] = None,
enable_suspend: Optional[FilterOrBool] = None,
system_prompt: Optional[FilterOrBool] = None,
suspend: Optional[FilterOrBool] = None,
enable_open_in_editor: Optional[FilterOrBool] = None,
tempfile_suffix: Optional[Union[str, Callable[[], str]]] = None,
tempfile: Optional[Union[str, Callable[[], str]]] = None,
Expand Down Expand Up @@ -1076,10 +1078,10 @@ class itself. For these, passing in ``None`` will keep the current
self.placeholder = placeholder
if reserve_space_for_menu is not None:
self.reserve_space_for_menu = reserve_space_for_menu
if enable_system_elicit is not None:
self.enable_system_elicit = enable_system_elicit
if enable_suspend is not None:
self.enable_suspend = enable_suspend
if system_prompt is not None:
self.system_prompt = system_prompt
if suspend is not None:
self.suspend = suspend
if enable_open_in_editor is not None:
self.enable_open_in_editor = enable_open_in_editor
if tempfile_suffix is not None:
Expand Down Expand Up @@ -1191,8 +1193,8 @@ async def elicit_async(
input_processors: Optional[List[Processor]] = None,
placeholder: Optional[AnyFormattedText] = None,
reserve_space_for_menu: Optional[int] = None,
enable_system_elicit: Optional[FilterOrBool] = None,
enable_suspend: Optional[FilterOrBool] = None,
system_prompt: Optional[FilterOrBool] = None,
suspend: Optional[FilterOrBool] = None,
enable_open_in_editor: Optional[FilterOrBool] = None,
tempfile_suffix: Optional[Union[str, Callable[[], str]]] = None,
tempfile: Optional[Union[str, Callable[[], str]]] = None,
Expand Down Expand Up @@ -1265,10 +1267,10 @@ async def elicit_async(
self.placeholder = placeholder
if reserve_space_for_menu is not None:
self.reserve_space_for_menu = reserve_space_for_menu
if enable_system_elicit is not None:
self.enable_system_elicit = enable_system_elicit
if enable_suspend is not None:
self.enable_suspend = enable_suspend
if system_prompt is not None:
self.system_prompt = system_prompt
if suspend is not None:
self.suspend = suspend
if enable_open_in_editor is not None:
self.enable_open_in_editor = enable_open_in_editor
if tempfile_suffix is not None:
Expand Down

0 comments on commit 1a2a2ec

Please sign in to comment.