Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the option not to include the extra newline of the Tree's __rich_console__ #3583

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion rich/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(
expanded: bool = True,
highlight: bool = False,
hide_root: bool = False,
end_new_line: bool = True,
) -> None:
self.label = label
self.style = style
Expand All @@ -51,6 +52,7 @@ def __init__(
self.expanded = expanded
self.highlight = highlight
self.hide_root = hide_root
self.end_new_line = end_new_line

def add(
self,
Expand Down Expand Up @@ -79,6 +81,7 @@ def add(
guide_style=self.guide_style if guide_style is None else guide_style,
expanded=expanded,
highlight=self.highlight if highlight is None else highlight,
end_new_line=True,
)
self.children.append(node)
return node
Expand Down Expand Up @@ -155,7 +158,11 @@ def make_guide(index: int, style: Style) -> Segment:
post_style=remove_guide_styles,
)
yield from line
yield new_line

# Equivalent of `if not last or (depth == 0) or (depth != 0 and self.end_new_line):`
if not last or depth == 0 or self.end_new_line:
yield new_line

if first and prefix:
prefix[-1] = make_guide(
SPACE if last else CONTINUE, prefix[-1].style or null_style
Expand Down