Combine a number of renderables and text into one renderable. Args: objects (Iterable[Any]): Anything that Rich can render. sep (str): String to write between print data. end (str): String to write at end of print data. justify (str, optional)
(
self,
objects: Iterable[Any],
sep: str,
end: str,
*,
justify: Optional[JustifyMethod] = None,
emoji: Optional[bool] = None,
markup: Optional[bool] = None,
highlight: Optional[bool] = None,
)
| 1498 | ) from None |
| 1499 | |
| 1500 | def _collect_renderables( |
| 1501 | self, |
| 1502 | objects: Iterable[Any], |
| 1503 | sep: str, |
| 1504 | end: str, |
| 1505 | *, |
| 1506 | justify: Optional[JustifyMethod] = None, |
| 1507 | emoji: Optional[bool] = None, |
| 1508 | markup: Optional[bool] = None, |
| 1509 | highlight: Optional[bool] = None, |
| 1510 | ) -> List[ConsoleRenderable]: |
| 1511 | """Combine a number of renderables and text into one renderable. |
| 1512 | |
| 1513 | Args: |
| 1514 | objects (Iterable[Any]): Anything that Rich can render. |
| 1515 | sep (str): String to write between print data. |
| 1516 | end (str): String to write at end of print data. |
| 1517 | justify (str, optional): One of "left", "right", "center", or "full". Defaults to ``None``. |
| 1518 | emoji (Optional[bool], optional): Enable emoji code, or ``None`` to use console default. |
| 1519 | markup (Optional[bool], optional): Enable markup, or ``None`` to use console default. |
| 1520 | highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use console default. |
| 1521 | |
| 1522 | Returns: |
| 1523 | List[ConsoleRenderable]: A list of things to render. |
| 1524 | """ |
| 1525 | |
| 1526 | def is_expandable(obj: object) -> bool: |
| 1527 | """Check if an object is expandable by pretty printer.""" |
| 1528 | # Permit lazy loading |
| 1529 | from .pretty import is_expandable as _is_expandable |
| 1530 | |
| 1531 | return _is_expandable(obj) |
| 1532 | |
| 1533 | renderables: List[ConsoleRenderable] = [] |
| 1534 | _append = renderables.append |
| 1535 | text: List[Text] = [] |
| 1536 | append_text = text.append |
| 1537 | |
| 1538 | append = _append |
| 1539 | if justify in ("left", "center", "right"): |
| 1540 | |
| 1541 | def align_append(renderable: RenderableType) -> None: |
| 1542 | _append(Align(renderable, cast(AlignMethod, justify))) |
| 1543 | |
| 1544 | append = align_append |
| 1545 | |
| 1546 | _highlighter: HighlighterType = _null_highlighter |
| 1547 | if highlight or (highlight is None and self._highlight): |
| 1548 | _highlighter = self.highlighter |
| 1549 | |
| 1550 | def check_text() -> None: |
| 1551 | if text: |
| 1552 | sep_text = Text(sep, justify=justify, end=end) |
| 1553 | append(sep_text.join(text)) |
| 1554 | text.clear() |
| 1555 | |
| 1556 | for renderable in objects: |
| 1557 | renderable = rich_cast(renderable) |
no test coverage detected