Skip to content
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] text justify "fully" egde-case with more than 1 space continuosly #3423

Closed
2 tasks done
oppZ opened this issue Jul 11, 2024 · 2 comments
Closed
2 tasks done

[BUG] text justify "fully" egde-case with more than 1 space continuosly #3423

oppZ opened this issue Jul 11, 2024 · 2 comments

Comments

@oppZ
Copy link

oppZ commented Jul 11, 2024

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.

My idea to fix this, would be to not add a space if the word in this position was already a space - preserve the spaces

Platform

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

Ubuntu 24.04

Copy link

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

@oppZ oppZ closed this as completed Jul 11, 2024
Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant