Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions Lib/_pyrepl/content.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from dataclasses import dataclass

from .utils import ColorSpan, StyleRef, THEME, iter_display_chars, unbracket, wlen
from _colorize import Syntax

from .utils import ColorSpan, StyleRef, iter_display_chars, unbracket, wlen


@dataclass(frozen=True, slots=True)
Expand Down Expand Up @@ -108,27 +110,14 @@ def build_body_fragments(
buffer: str,
colors: list[ColorSpan] | None,
start_index: int,
theme: Syntax,
) -> tuple[ContentFragment, ...]:
"""Convert a line's text into styled content fragments."""
# Two separate loops to avoid the THEME() call in the common uncolored path.
if colors is None:
return tuple(
ContentFragment(
styled_char.text,
styled_char.width,
StyleRef(),
)
for styled_char in iter_display_chars(buffer, colors, start_index)
)

theme = THEME()
return tuple(
ContentFragment(
styled_char.text,
styled_char.width,
StyleRef.from_tag(styled_char.tag, theme[styled_char.tag])
if styled_char.tag
else StyleRef(),
)
for styled_char in iter_display_chars(buffer, colors, start_index)
)
plain = StyleRef()
style = plain
fragments = []
for text, width, tag in iter_display_chars(buffer, colors, start_index):
if tag != style.tag:
style = StyleRef.from_tag(tag, theme[tag]) if tag else plain
fragments.append(ContentFragment(text, width, style))
return tuple(fragments)
7 changes: 4 additions & 3 deletions Lib/_pyrepl/historical_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,13 @@ def prepare(self) -> None:
self.restore()
raise

def get_prompt(self, lineno: int, cursor_on_line: bool) -> str:
def _prompt_for_line(
self, lineno: int, cursor_on_line: bool, *, last_lineno: int | None,
) -> str:
if cursor_on_line and self.isearch_direction != ISEARCH_DIRECTION_NONE:
d = "rf"[self.isearch_direction == ISEARCH_DIRECTION_FORWARDS]
return "(%s-search `%s') " % (d, self.isearch_term)
else:
return super().get_prompt(lineno, cursor_on_line)
return super()._prompt_for_line(lineno, cursor_on_line, last_lineno=last_lineno)

def search_next(self, *, forwards: bool) -> None:
"""Search history for the current line contents up to the cursor.
Expand Down
Loading
Loading