Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
48.1k stars 1.69k forks source link

Tree: ASCII_GUIDES and TREE_GUIDES promoted to class attributes #3378

Closed jdvanwijk closed 1 day ago

jdvanwijk commented 3 weeks ago

Type of changes

Checklist

Description

In the Tree class, I have promoted the ASCII_GUIDES and TREE_GUIDES constants (previously located within the __rich_console__ method) to class attributes. Additionally, I have updated the Tree class docstring to reflect this change.

This modification simplifies the process of customizing the appearance of tree guides. Users can now easily inherit from the Tree class and modify its class attributes directly, rather than delving into the __rich_console__ method.

jdvanwijk commented 3 weeks ago

Example use:

class WideTree(Tree):
    ASCII_GUIDES = ("        ", "|       ", "+------- ", "`------- ")
    TREE_GUIDES = [
        ("        ", "│       ", "├────── ", "└────── "),
        ("        ", "┃       ", "┣━━━━━━ ", "┗━━━━━━ "),
        ("        ", "║       ", "╠══════ ", "╚══════ "),
    ]