-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[BUG] #3188
Comments
From https://rich.readthedocs.io/en/stable/protocol.html#measuring-renderables
This doesn't seem to work with a simple from rich.console import Console, ConsoleOptions, RenderResult
from rich.measure import Measurement
from rich.table import Table
class Employee:
def __init__(self, name: str) -> None:
self.name = name
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
yield self.name
def __rich_measure__(
self, console: Console, options: ConsoleOptions
) -> Measurement:
return Measurement(len(self.name), len(self.name))
console = Console()
table = Table()
table.add_column("Name", no_wrap=True)
table.add_column("Age")
table.add_row(Employee("John Doe"), "42")
console.print(table) |
I hope we solved your problem. If you like using Rich, you might also enjoy Textual |
Classes that implement a
__rich__
-method aren't rendered correctly in tables:Example
Yields this result:
Removing
no_wrap=True
renders at least the second column, but makes theName
column to wide:Calling
Employee("John Doe").__rich__()
explicitly gives the expected result:Click to expand
The text was updated successfully, but these errors were encountered: