Skip to content

Commit 6b632ce

Browse files
pythongh-139167: Allow users to hook gen_colors function to pyrepl Reader (python#141619)
1 parent 7c9ad27 commit 6b632ce

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Lib/_pyrepl/reader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@
3838
)
3939
from .layout import LayoutMap, LayoutResult, LayoutRow, WrappedRow, layout_content_lines
4040
from .render import RenderCell, RenderLine, RenderedScreen, ScreenOverlay
41-
from .utils import ANSI_ESCAPE_SEQUENCE, THEME, StyleRef, wlen, gen_colors
41+
from .utils import ANSI_ESCAPE_SEQUENCE, ColorSpan, THEME, StyleRef, wlen, gen_colors
4242
from .trace import trace
4343

4444

4545
# types
4646
Command = commands.Command
47+
from collections.abc import Callable, Iterator
4748
from .types import (
4849
Callback,
4950
CommandName,
@@ -304,6 +305,7 @@ class Reader:
304305
lxy: CursorXY = field(init=False)
305306
scheduled_commands: list[CommandName] = field(default_factory=list)
306307
can_colorize: bool = False
308+
gen_colors: Callable[[str], Iterator[ColorSpan]] = gen_colors
307309
threading_hook: Callback | None = None
308310
invalidation: RefreshInvalidation = field(init=False)
309311

@@ -534,7 +536,7 @@ def _build_content_lines(
534536
prompt_from_cache: bool,
535537
) -> tuple[ContentLine, ...]:
536538
if self.can_colorize:
537-
colors = list(gen_colors(self.get_unicode()))
539+
colors = list(self.gen_colors(self.get_unicode()))
538540
else:
539541
colors = None
540542
trace("colors = {colors}", colors=colors)

0 commit comments

Comments
 (0)