mirror of https://github.com/Textualize/rich.git
tree documentation
This commit is contained in:
parent
63135caeba
commit
4a9ed9c53a
|
@ -20,15 +20,16 @@ Welcome to Rich's documentation!
|
||||||
traceback.rst
|
traceback.rst
|
||||||
prompt.rst
|
prompt.rst
|
||||||
|
|
||||||
tables.rst
|
columns.rst
|
||||||
|
group.rst
|
||||||
|
live.rst
|
||||||
|
markdown.rst
|
||||||
padding.rst
|
padding.rst
|
||||||
panel.rst
|
panel.rst
|
||||||
group.rst
|
|
||||||
columns.rst
|
|
||||||
live.rst
|
|
||||||
progress.rst
|
progress.rst
|
||||||
markdown.rst
|
|
||||||
syntax.rst
|
syntax.rst
|
||||||
|
tables.rst
|
||||||
|
tree.rst
|
||||||
|
|
||||||
protocol.rst
|
protocol.rst
|
||||||
|
|
||||||
|
|
|
@ -35,4 +35,5 @@ Reference
|
||||||
reference/text.rst
|
reference/text.rst
|
||||||
reference/theme.rst
|
reference/theme.rst
|
||||||
reference/traceback.rst
|
reference/traceback.rst
|
||||||
|
reference/tree.rst
|
||||||
references/abc.rst
|
references/abc.rst
|
||||||
|
|
|
@ -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::
|
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
|
from rich.text import Text
|
||||||
|
|
||||||
|
console = Console()
|
||||||
text = Text("Hello, World!")
|
text = Text("Hello, World!")
|
||||||
text.stylize("bold magenta", 0, 6)
|
text.stylize("bold magenta", 0, 6)
|
||||||
console.print(text)
|
console.print(text)
|
||||||
|
|
14
rich/tree.py
14
rich/tree.py
|
@ -12,7 +12,7 @@ class Tree(JupyterMixin):
|
||||||
"""A renderable for a tree structure.
|
"""A renderable for a tree structure.
|
||||||
|
|
||||||
Args:
|
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".
|
style (StyleType, optional): Style of this tree. Defaults to "tree".
|
||||||
guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
|
guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
|
||||||
expanded (bool, optional): Also display children. Defaults to True.
|
expanded (bool, optional): Also display children. Defaults to True.
|
||||||
|
@ -21,14 +21,14 @@ class Tree(JupyterMixin):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
renderable: RenderableType,
|
label: RenderableType,
|
||||||
*,
|
*,
|
||||||
style: StyleType = "tree",
|
style: StyleType = "tree",
|
||||||
guide_style: StyleType = "tree.line",
|
guide_style: StyleType = "tree.line",
|
||||||
expanded=True,
|
expanded=True,
|
||||||
highlight=False,
|
highlight=False,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.renderable = renderable
|
self.label = label
|
||||||
self.style = style
|
self.style = style
|
||||||
self.guide_style = guide_style
|
self.guide_style = guide_style
|
||||||
self.children: List[Tree] = []
|
self.children: List[Tree] = []
|
||||||
|
@ -37,7 +37,7 @@ class Tree(JupyterMixin):
|
||||||
|
|
||||||
def add(
|
def add(
|
||||||
self,
|
self,
|
||||||
renderable: RenderableType,
|
label: RenderableType,
|
||||||
*,
|
*,
|
||||||
style: StyleType = None,
|
style: StyleType = None,
|
||||||
guide_style: StyleType = None,
|
guide_style: StyleType = None,
|
||||||
|
@ -47,7 +47,7 @@ class Tree(JupyterMixin):
|
||||||
"""Add a child tree.
|
"""Add a child tree.
|
||||||
|
|
||||||
Args:
|
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".
|
style (StyleType, optional): Style of this tree. Defaults to "tree".
|
||||||
guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
|
guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
|
||||||
expanded (bool, optional): Also display children. Defaults to True.
|
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.
|
Tree: A new child Tree, which may be further modified.
|
||||||
"""
|
"""
|
||||||
node = Tree(
|
node = Tree(
|
||||||
renderable,
|
label,
|
||||||
style=self.style if style is None else style,
|
style=self.style if style is None else style,
|
||||||
guide_style=self.guide_style if guide_style is None else guide_style,
|
guide_style=self.guide_style if guide_style is None else guide_style,
|
||||||
expanded=expanded,
|
expanded=expanded,
|
||||||
|
@ -123,7 +123,7 @@ class Tree(JupyterMixin):
|
||||||
style = style_stack.current + get_style(node.style)
|
style = style_stack.current + get_style(node.style)
|
||||||
prefix = levels[1:]
|
prefix = levels[1:]
|
||||||
renderable_lines = console.render_lines(
|
renderable_lines = console.render_lines(
|
||||||
Styled(node.renderable, style),
|
Styled(node.label, style),
|
||||||
options.update(
|
options.update(
|
||||||
width=options.max_width
|
width=options.max_width
|
||||||
- sum(level.cell_length for level in prefix),
|
- sum(level.cell_length for level in prefix),
|
||||||
|
|
Loading…
Reference in New Issue