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.81k stars 1.71k forks source link

[BUG] The size of the tab is not fixed when justifying the text on "fully" #3424

Open oppZ opened 1 month ago

oppZ commented 1 month ago

Describe the bug

I'm coming from textual, the tui framework. I was printing paragraphs in Label and added a \t before each to add a tab. As I was resizing the window, I noticed that some paragraphs were not aligned anymore - some had extra spaces. I have set the css of that label to "text-align: justify;" to justify it fully - (from left to right).

Here is how the issue looks like :

demo

As you can see, the space of the indentation for the first paragraph changes.

I tracked down the issue and these are my findings :

In textual, \t is converted with 8 spaces and uses rich to split and justify the text In rich, the text is split for each word using " " so a space. Problem is, the 8 spaces from textual are treated as 8 words in addition to the "real" ones. Therefore, in the current implementation when the text is justified, space are set between words, but the spaces are too.

Below is rich in debug mode of the containers.py file :

Screenshot from 2024-07-11 21-31-22

You can see that the first line is split by " " and the variable "spaces" hold the amount of spaces to append for each word. In he "spaces" variable the first "words" (spaces) have more than 1 space, therefore spaces are also considered as words.

The issue here is that the tab (\t) is converted to spaces and these spaces are justified and so the size of the tab is bigger than the default 8

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?

ubunu 24.04

github-actions[bot] commented 1 month ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory