tree documentation

This commit is contained in:
Will McGugan 2021-01-09 15:28:04 +00:00
parent 63135caeba
commit 4a9ed9c53a
4 changed files with 17 additions and 12 deletions

View File

@ -20,15 +20,16 @@ Welcome to Rich's documentation!
traceback.rst
prompt.rst
tables.rst
columns.rst
group.rst
live.rst
markdown.rst
padding.rst
panel.rst
group.rst
columns.rst
live.rst
progress.rst
markdown.rst
syntax.rst
tables.rst
tree.rst
protocol.rst

View File

@ -35,4 +35,5 @@ Reference
reference/text.rst
reference/theme.rst
reference/traceback.rst
reference/tree.rst
references/abc.rst

View File

@ -9,7 +9,10 @@ You can consider this class to be like a string with marked up regions of text.
One way to add a style to Text is the :meth:`~rich.text.Text.stylize` method which applies a style to a start and end offset. Here is an example::
from rich.console import Console
from rich.text import Text
console = Console()
text = Text("Hello, World!")
text.stylize("bold magenta", 0, 6)
console.print(text)

View File

@ -12,7 +12,7 @@ class Tree(JupyterMixin):
"""A renderable for a tree structure.
Args:
renderable (RenderableType): The renderable or str for the tree label.
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.
@ -21,14 +21,14 @@ class Tree(JupyterMixin):
def __init__(
self,
renderable: RenderableType,
label: RenderableType,
*,
style: StyleType = "tree",
guide_style: StyleType = "tree.line",
expanded=True,
highlight=False,
) -> None:
self.renderable = renderable
self.label = label
self.style = style
self.guide_style = guide_style
self.children: List[Tree] = []
@ -37,7 +37,7 @@ class Tree(JupyterMixin):
def add(
self,
renderable: RenderableType,
label: RenderableType,
*,
style: StyleType = None,
guide_style: StyleType = None,
@ -47,7 +47,7 @@ class Tree(JupyterMixin):
"""Add a child tree.
Args:
renderable (RenderableType): The renderable or str for the tree label.
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.
@ -57,7 +57,7 @@ class Tree(JupyterMixin):
Tree: A new child Tree, which may be further modified.
"""
node = Tree(
renderable,
label,
style=self.style if style is None else style,
guide_style=self.guide_style if guide_style is None else guide_style,
expanded=expanded,
@ -123,7 +123,7 @@ class Tree(JupyterMixin):
style = style_stack.current + get_style(node.style)
prefix = levels[1:]
renderable_lines = console.render_lines(
Styled(node.renderable, style),
Styled(node.label, style),
options.update(
width=options.max_width
- sum(level.cell_length for level in prefix),