Skip to content

Commit

Permalink
Make formatted_text.split_lines accept an iterable (type annotation o…
Browse files Browse the repository at this point in the history
…nly).
  • Loading branch information
jonathanslenders committed Dec 12, 2023
1 parent 55cde3e commit 8c8840c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/prompt_toolkit/formatted_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .base import (
AnyFormattedText,
FormattedText,
OneStyleAndTextTuple,
StyleAndTextTuples,
Template,
is_formatted_text,
Expand All @@ -35,6 +36,7 @@
__all__ = [
# Base.
"AnyFormattedText",
"OneStyleAndTextTuple",
"to_formatted_text",
"is_formatted_text",
"Template",
Expand Down
8 changes: 5 additions & 3 deletions src/prompt_toolkit/formatted_text/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ def fragment_list_to_text(fragments: StyleAndTextTuples) -> str:
return "".join(item[1] for item in fragments if ZeroWidthEscape not in item[0])


def split_lines(fragments: StyleAndTextTuples) -> Iterable[StyleAndTextTuples]:
def split_lines(
fragments: Iterable[OneStyleAndTextTuple],
) -> Iterable[StyleAndTextTuples]:
"""
Take a single list of (style_str, text) tuples and yield one such list for each
line. Just like str.split, this will yield at least one item.
:param fragments: List of (style_str, text) or (style_str, text, mouse_handler)
tuples.
:param fragments: Iterable of ``(style_str, text)`` or
``(style_str, text, mouse_handler)`` tuples.
"""
line: StyleAndTextTuples = []

Expand Down

0 comments on commit 8c8840c

Please sign in to comment.