Skip to content

A few beginner questions #867

Answered by willmcgugan
ronf asked this question in Q&A
Discussion options

You must be logged in to vote

That wouldn't work I'm afraid. But the principle is correct.

You should probably create a new component which renders a child component with a prefix. In the __rich_console__ method call render_lines with a smaller width, then yield the prefix + line for each line.

Something like this (untested).

class WithPrefix:

    def __init__(self, renderable) -> None:
        self.renderable = renderable

    def __rich_console__(
        self, console: Console, options: ConsoleOptions
    ) -> RenderResult:
        render_options = options.update(width=options.max_width - 2)
        lines = console.render_lines(self.renderable, render_options)
        new_line = Segment("\n")
        padding = Seg…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ronf
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants