Skip to content

Expose raw parameter from prompt-toolkit to allow escape sequences. #615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ptpython

pip install ptpython

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/example1.png
.. image :: ./docs/images/example1.png

Ptpython is an advanced Python REPL. It should work on all
Python versions from 2.6 up to 3.11 and work cross platform (Linux,
Expand Down Expand Up @@ -109,15 +109,15 @@ More screenshots

The configuration menu:

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/ptpython-menu.png
.. image :: ./docs/images/ptpython-menu.png

The history page and its help:

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/ptpython-history-help.png
.. image :: ./docs/images/ptpython-history-help.png

Autocompletion:

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/file-completion.png
.. image :: ./docs/images/file-completion.png


Embedding the REPL
Expand Down Expand Up @@ -159,7 +159,7 @@ terminal, you have to check the "Use option as meta key" checkbox in your
terminal settings. For iTerm2, you have to check "Left option acts as +Esc" in
the options.)

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/multiline.png
.. image :: ./docs/images/multiline.png


Syntax validation
Expand All @@ -169,7 +169,7 @@ Before execution, ``ptpython`` will see whether the input is syntactically
correct Python code. If not, it will show a warning, and move the cursor to the
error.

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/validation.png
.. image :: ./docs/images/validation.png


Asyncio REPL and top level await
Expand Down Expand Up @@ -208,7 +208,7 @@ variable, if set, can also be used to explicitly override where configuration
is looked for.

Have a look at this example to see what is possible:
`config.py <https://github.com/jonathanslenders/ptpython/blob/master/examples/ptpython_config/config.py>`_
`config.py <https://github.com/prompt-toolkit/ptpython/blob/master/examples/ptpython_config/config.py>`_

Note config file support currently only works when invoking `ptpython` directly.
That it, the config file will be ignored when embedding ptpython in an application.
Expand All @@ -222,7 +222,7 @@ with all the power that IPython has to offer, like magic functions and shell
integration. Make sure that IPython has been installed. (``pip install
ipython``)

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/ipython.png
.. image :: ./docs/images/ipython.png

This is also available for embedding:

Expand Down Expand Up @@ -253,7 +253,7 @@ Windows support
``prompt_toolkit`` and ``ptpython`` works better on Linux and OS X than on
Windows. Some things might not work, but it is usable:

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/windows.png
.. image :: ./docs/images/windows.png

Windows terminal integration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 5 additions & 1 deletion src/ptpython/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ def embed(
title: str | None = ...,
startup_paths: Sequence[str | Path] | None = ...,
patch_stdout: bool = ...,
patch_stdout_raw: bool = ...,
return_asyncio_coroutine: Literal[False] = ...,
) -> None: ...

Expand All @@ -539,6 +540,7 @@ def embed(
title: str | None = ...,
startup_paths: Sequence[str | Path] | None = ...,
patch_stdout: bool = ...,
patch_stdout_raw: bool = ...,
return_asyncio_coroutine: Literal[True] = ...,
) -> Coroutine[Any, Any, None]: ...

Expand All @@ -552,6 +554,7 @@ def embed(
title: str | None = None,
startup_paths: Sequence[str | Path] | None = None,
patch_stdout: bool = False,
patch_stdout_raw: bool = False,
return_asyncio_coroutine: bool = False,
) -> None | Coroutine[Any, Any, None]:
"""
Expand All @@ -567,6 +570,7 @@ def embed(
:param title: Title to be displayed in the terminal titlebar. (None or string.)
:param patch_stdout: When true, patch `sys.stdout` so that background
threads that are printing will print nicely above the prompt.
:param patch_stdout_raw: When true, patch_stdout will not escape/remove vt100 terminal escape sequences.
"""
# Default globals/locals
if globals is None:
Expand Down Expand Up @@ -602,7 +606,7 @@ def get_locals() -> dict[str, Any]:

# Start repl.
patch_context: ContextManager[None] = (
patch_stdout_context() if patch_stdout else DummyContext()
patch_stdout_context(raw=patch_stdout_raw) if patch_stdout else DummyContext()
)

if return_asyncio_coroutine:
Expand Down