Skip to content
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
6 changes: 4 additions & 2 deletions Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
from dataclasses import dataclass, field, fields

from . import commands, console, input
from .utils import wlen, unbracket, disp_str, gen_colors, THEME
from .utils import wlen, unbracket, disp_str, gen_colors, ColorSpan, THEME
from .trace import trace


# types
Command = commands.Command
from collections.abc import Callable, Iterator
from .types import Callback, SimpleContextManager, KeySpec, CommandName


Expand Down Expand Up @@ -213,6 +214,7 @@ class Reader:
lxy: tuple[int, int] = field(init=False)
scheduled_commands: list[str] = field(default_factory=list)
can_colorize: bool = False
gen_colors: Callable[[str], Iterator[ColorSpan]] = field(default=gen_colors)
threading_hook: Callback | None = None

## cached metadata to speed up screen refreshes
Expand Down Expand Up @@ -312,7 +314,7 @@ def calc_screen(self) -> list[str]:
prompt_from_cache = (offset and self.buffer[offset - 1] != "\n")

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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow users to use customized ``gen_colors`` function for pyrepl ``Reader``.
Loading