Open rjbs opened 1 year ago
You have given Rich an impossible to satisfy set of restraints. The first three columns are fixed, and the last isn't permitted to wrap. There is no way to shrink that without breaking at least one constraint, so it defaults to a "last resort" algorithm to compress the table.
A workaround would be to remove the constraints from the columns and prevent the cell from wrapping.
from rich import print
from rich.table import Table
from rich.text import Text
table = Table(show_header=True, header_style="bold magenta", expand=True)
table.add_column("Issue")
table.add_column("S")
table.add_column("Pri")
table.add_column("Title")
too_long = """\
This is a full line sentence and it fills a whole line so it overflows a cell!\
"""
for i in range(2):
table.add_row(
"ABC-123",
"X",
"123",
Text(" ".join([too_long, too_long]), no_wrap=True),
)
print(table)
Thanks, @willmcgugan, that does get me the behavior that I wanted. I really appreciate it.
I'd like to ask a follow-up question, if I may. You said, "You have given Rich an impossible to satisfy set of restraints." and I reckon you're right! But I would've thought the model worked differently, and I think I'll do better moving forward if I understand it more. Maybe you can speak the three words that will enlighten me, or just point me at something for me to read over and over until it clicks. :)
You wrote:
The first three columns are fixed, and the last isn't permitted to wrap. There is no way to shrink that without breaking at least one constraint, so it defaults to a "last resort" algorithm to compress the table.
I would have thought that it would be able to be satisfied like so:
I suspect that my misunderstanding is related to the way in which the no_wrap/overflow of the column are communicated to, or share dependency ordering with, the renderable in each row of the column, but I'm afraid I don't understand my own understanding.
If you can clear it up, I would be grateful. If not, well, I'm already grateful for the above. Thanks!
I struggled with this exact problem for a long time, and @willmcgugan solution also worked perfectly for me.
To be honest, I'm not sure I understand the difference between a column not being allowed to wrap vs a cell not being able to wrap...
For the reference of anyone reading, the workaround gives the following (desired) output:
>>> print("x"*80)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>> print(table)
โโโโโโโโโโโณโโโโณโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Issue โ S โ Pri โ Title โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ ABC-123 โ X โ 123 โ This is a full line sentence and it fills a whole line โฆ โ
โ ABC-123 โ X โ 123 โ This is a full line sentence and it fills a whole line โฆ โ
โโโโโโโโโโโดโโโโดโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Describe the bug
I'll start with: the bug may be with my understanding of options, so I'm prepared to accept that I'm thinking about things wrong. That said, I feel pretty confident that my thinking is not incoherent. ๐
In a tableย column, the no_wrap option does not function as I would expect. My expectation is that the content of a column would not be allowed to wrap, and that the overflow property would apply. Further, that with no specification of the column's width, its width would be determined by finding the total available table width, meeting the width requirements of other columns (and borders) and then using the remaining space.
Instead, a no_wrap column is forcingย other table column contents to be squashed below their minimum width. Consider this program:
This prints the following table on my 80 column terminal (iTerm2):
If I update the program to use no_wrap:
...then the table produced squashes the first three columns below their minimum before applying the ellipsis overflow behavior.
I think instead, the left columns should be displayed at their specified widths, and the rightmost column truncated earlier.
Platform
Click to expand
What platform (Win/Linux/Mac) are you running on? What terminal software are you using? I'm running on macOS Venture: ``` Darwin snowdrop 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:43 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T8112 arm64 ``` I'm using iTerm2 v3.4.19.rich.diagnose
โโโโโโโโโโโโโโโโโโโโโโโโฎ โ A high level console interface. โ โ โ โ โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ โ โ โpip freeze | grep rich
``` snowdrop:~/fm/code/glinpy$ pip freeze | grep rich rich==13.3.2 ```