from typing import Iterator, List, Optional, Tuple
from ._loop import loop_first, loop_last from .console import Console, ConsoleOptions, RenderableType, RenderResult from .jupyter import JupyterMixin from .measure import Measurement from .segment import Segment from .style import Style, StyleStack, StyleType from .styled import Styled
GuideType = Tuple[str, str, str, str]
class Tree(JupyterMixin): """A renderable for a tree structure.
Attributes:
ASCII_GUIDES (GuideType): Guide lines used when Console.ascii_only isTrue.
TREE_GUIDES (List[GuideType, GuideType, GuideType]): Default guide lines.
Args:
label (RenderableType): The renderable or str for the tree label.
style (StyleType, optional): Style of this tree. Defaults to "tree".
guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
expanded (bool, optional): Also display children. Defaults to True.
highlight (bool, optional): Highlight renderable (if str). Defaults to False.
hide_root (bool, optional): Hide the root node. Defaults to False. """
Args:
label (RenderableType): The renderable or str for the tree label.
style (StyleType, optional): Style of this tree. Defaults to "tree".
guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
expanded (bool, optional): Also display children. Defaults to True.
highlight (Optional[bool], optional): Highlight renderable (if str). Defaults to False.
Returns:
Tree: A new child Tree, which may be further modified. """
node = Tree(
label,
style=self.style if style isNoneelse style,
guide_style=self.guide_style if guide_style isNoneelse guide_style,
expanded=expanded,
highlight=self.highlight if highlight isNoneelse highlight,
)
self.children.append(node) return node
get_style = console.get_style
null_style = Style.null()
guide_style = get_style(self.guide_style, default="") or null_style
SPACE, CONTINUE, FORK, END = range(4)
_Segment = Segment
def make_guide(index: int, style: Style) -> Segment: """Make a Segment for a level of the guide lines.""" if options.ascii_only:
line = self.ASCII_GUIDES[index] else:
guide = 1 if style.bold else (2 if style.underline2 else 0)
line = self.TREE_GUIDES[0 if options.legacy_windows else guide][index] return _Segment(line, style)
ifnot (depth == 0 and self.hide_root): for first, line in loop_first(renderable_lines): if prefix: yieldfrom _Segment.apply_style(
prefix,
style.background_style,
post_style=remove_guide_styles,
) yieldfrom line yield new_line if first and prefix:
prefix[-1] = make_guide(
SPACE if last elseCONTINUE, prefix[-1].style or null_style
)
if node.expanded and node.children:
levels[-1] = make_guide(
SPACE if last elseCONTINUE, levels[-1].style or null_style
)
levels.append(
make_guide(END if len(node.children) == 1 else FORK, guide_style)
)
style_stack.push(get_style(node.style))
guide_style_stack.push(get_style(node.guide_style))
push(iter(loop_last(node.children)))
depth += 1
if __name__ == "__main__": # pragma: no cover from rich.console import Group from rich.markdown import Markdown from rich.panel import Panel from rich.syntax import Syntax from rich.table import Table
table.add_row("Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$952,110,690")
table.add_row("May 25, 2018", "Solo: A Star Wars Story", "$393,151,347")
table.add_row("Dec 15, 2017", "Star Wars Ep. V111: The Last Jedi", "$1,332,539,889")
table.add_row("Dec 16, 2016", "Rogue One: A Star Wars Story", "$1,332,439,889")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.