https://github.com/python/cpython/commit/6b632ce36b950c7753c5e8c79d306af85f10db40
commit: 6b632ce36b950c7753c5e8c79d306af85f10db40
branch: main
author: Tian Gao <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2026-05-02T13:28:00-07:00
summary:
gh-139167: Allow users to hook gen_colors function to pyrepl Reader (#141619)
files:
M Lib/_pyrepl/reader.py
diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py
index b8e1e425b0bb35..7e4dd801c84d5c 100644
--- a/Lib/_pyrepl/reader.py
+++ b/Lib/_pyrepl/reader.py
@@ -38,12 +38,13 @@
)
from .layout import LayoutMap, LayoutResult, LayoutRow, WrappedRow,
layout_content_lines
from .render import RenderCell, RenderLine, RenderedScreen, ScreenOverlay
-from .utils import ANSI_ESCAPE_SEQUENCE, THEME, StyleRef, wlen, gen_colors
+from .utils import ANSI_ESCAPE_SEQUENCE, ColorSpan, THEME, StyleRef, wlen,
gen_colors
from .trace import trace
# types
Command = commands.Command
+from collections.abc import Callable, Iterator
from .types import (
Callback,
CommandName,
@@ -304,6 +305,7 @@ class Reader:
lxy: CursorXY = field(init=False)
scheduled_commands: list[CommandName] = field(default_factory=list)
can_colorize: bool = False
+ gen_colors: Callable[[str], Iterator[ColorSpan]] = gen_colors
threading_hook: Callback | None = None
invalidation: RefreshInvalidation = field(init=False)
@@ -534,7 +536,7 @@ def _build_content_lines(
prompt_from_cache: bool,
) -> tuple[ContentLine, ...]:
if self.can_colorize:
- colors = list(gen_colors(self.get_unicode()))
+ colors = list(self.gen_colors(self.get_unicode()))
else:
colors = None
trace("colors = {colors}", colors=colors)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]