Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Grapheme clusters width miscalculation #4375

Closed
haliphax opened this issue Apr 1, 2024 · 4 comments
Closed

Grapheme clusters width miscalculation #4375

haliphax opened this issue Apr 1, 2024 · 4 comments

Comments

@haliphax
Copy link

haliphax commented Apr 1, 2024

It seems as though grapheme clusters (e.g. anything using skin tone modifiers, emoji variant selector, flags, etc.) are not properly accounted for when calculating the width of things. In the example program below, the scroll bar on initial load looks like a jagged mess. While it will smooth out after scrolling around a bit, a periodic refresh will break it again. I have seen some similar issues with placement of widgets on top of widgets containing grapheme clusters, as well (e.g. modal screens).

from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Static


class ExampleApp(App):
    def compose(self) -> ComposeResult:
        yield VerticalScroll(Static())

    def on_mount(self) -> None:
        widget = self.query_one(Static)
        widget.update("Grapheme clusters ✌️ 🧑‍🚒\n\n" * self.size.height)


if __name__ == "__main__":
    ExampleApp().run()

image

Copy link

github-actions bot commented Apr 1, 2024

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@haliphax
Copy link
Author

haliphax commented Apr 1, 2024

Example with overlaying widgets:

image

@TomJGooding
Copy link
Contributor

TomJGooding commented Apr 1, 2024

Unfortunately there's nothing Textual can do about it, based on a reply by @willmcgugan to this similar issue #3040 about emojis:

I'm assuming this is just a classic emoji issue. Terminals don't agree on how wide they should be. Not much we can do about it alas.

@willmcgugan
Copy link
Collaborator

Yes, terminals render multi-codepoint emojis differently. And there is no way to know exactly how they will render

@Textualize Textualize locked and limited conversation to collaborators Apr 1, 2024
@willmcgugan willmcgugan converted this issue into discussion #4377 Apr 1, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants