Skip to content
Merged
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
9 changes: 5 additions & 4 deletions python_files/pythonrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ def _initialize():
if sys.version_info >= (3, 13):
import re

import _pyrepl.simple_interact
import _pyrepl.utils

_pyrepl.utils.ANSI_ESCAPE_SEQUENCE = re.compile(
r"\x1b(?:\[[ -@]*[A-~]|\][^\x1b\x07]*(?:\x07|\x1b\\))"
)
_ansi_escape_sequence = re.compile(r"\x1b(?:\[[ -@]*[A-~]|\][^\x1b\x07]*(?:\x07|\x1b\\))")
_pyrepl.utils.ANSI_ESCAPE_SEQUENCE = _ansi_escape_sequence

# Import again to ensure the module is loaded after patching the ANSI_ESCAPE_SEQUENCE
import _pyrepl.simple_interact

# Patch _pyrepl.simple_interact.multiline_input to ensure prompts are strings
_original_multiline_input = _pyrepl.simple_interact.multiline_input
Expand Down
12 changes: 12 additions & 0 deletions python_files/tests/test_shell_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ def test_replacement_regex_preserves_csi_handling():
)


def test_replacement_regex_is_imported_by_pyrepl_modules():
if sys.version_info < (3, 15):
return

pyrepl_reader = importlib.import_module("_pyrepl.reader")
pyrepl_render = importlib.import_module("_pyrepl.render")

assert pyrepl_reader.ANSI_ESCAPE_SEQUENCE.sub("", "\x1b]633;A\x07>>> ") == ">>> "
assert pyrepl_render.ANSI_ESCAPE_SEQUENCE.sub("", "\x1b]633;A\x07>>> ") == ">>> "
assert pyrepl_render.RenderLine.from_rendered_text("\x1b]633;A\x07>>> ").width == 4


def test_pyrepl_multiline_input_converts_prompts_to_strings(monkeypatch):
if sys.version_info < (3, 13):
return
Expand Down
Loading