(
self, console: "Console", options: "ConsoleOptions"
)
| 84 | return node |
| 85 | |
| 86 | def __rich_console__( |
| 87 | self, console: class="st">"Console", options: class="st">"ConsoleOptions" |
| 88 | ) -> class="st">"RenderResult": |
| 89 | stack: List[Iterator[Tuple[bool, Tree]]] = [] |
| 90 | pop = stack.pop |
| 91 | push = stack.append |
| 92 | new_line = Segment.line() |
| 93 | |
| 94 | get_style = console.get_style |
| 95 | null_style = Style.null() |
| 96 | guide_style = get_style(self.guide_style, default=class="st">"") or null_style |
| 97 | SPACE, CONTINUE, FORK, END = range(4) |
| 98 | |
| 99 | _Segment = Segment |
| 100 | |
| 101 | def make_guide(index: int, style: Style) -> Segment: |
| 102 | class="st">""class="st">"Make a Segment for a level of the guide lines."class="st">"" |
| 103 | if options.ascii_only: |
| 104 | line = self.ASCII_GUIDES[index] |
| 105 | else: |
| 106 | guide = 1 if style.bold else (2 if style.underline2 else 0) |
| 107 | line = self.TREE_GUIDES[0 if options.legacy_windows else guide][index] |
| 108 | return _Segment(line, style) |
| 109 | |
| 110 | levels: List[Segment] = [make_guide(CONTINUE, guide_style)] |
| 111 | push(iter(loop_last([self]))) |
| 112 | |
| 113 | guide_style_stack = StyleStack(get_style(self.guide_style)) |
| 114 | style_stack = StyleStack(get_style(self.style)) |
| 115 | remove_guide_styles = Style(bold=False, underline2=False) |
| 116 | |
| 117 | depth = 0 |
| 118 | |
| 119 | while stack: |
| 120 | stack_node = pop() |
| 121 | try: |
| 122 | last, node = next(stack_node) |
| 123 | except StopIteration: |
| 124 | levels.pop() |
| 125 | if levels: |
| 126 | guide_style = levels[-1].style or null_style |
| 127 | levels[-1] = make_guide(FORK, guide_style) |
| 128 | guide_style_stack.pop() |
| 129 | style_stack.pop() |
| 130 | continue |
| 131 | push(stack_node) |
| 132 | if last: |
| 133 | levels[-1] = make_guide(END, levels[-1].style or null_style) |
| 134 | |
| 135 | guide_style = guide_style_stack.current + get_style(node.guide_style) |
| 136 | style = style_stack.current + get_style(node.style) |
| 137 | prefix = levels[(2 if self.hide_root else 1) :] |
| 138 | renderable_lines = console.render_lines( |
| 139 | Styled(node.label, style), |
| 140 | options.update( |
| 141 | width=options.max_width |
| 142 | - sum(level.cell_length for level in prefix), |
| 143 | highlight=self.highlight, |
nothing calls this directly
no test coverage detected