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

On CJK wide characters #40

Open
tjwei opened this issue Oct 12, 2024 · 0 comments
Open

On CJK wide characters #40

tjwei opened this issue Oct 12, 2024 · 0 comments

Comments

@tjwei
Copy link

tjwei commented Oct 12, 2024

This is an enhancement suggestion for supporting CJK wide characters.

Many CJK characters are two columns wide in terminals. For example, "人" is a Chinese character and appears as wide as "xx" in a terminal, though len("人")==1. Many calculations and codes are based on the assumption that each character take only occupies one column. This issue breaks many of the effects like in beams, the vertical beams break into segments and in print the rows are not cleaned correctly because the length of rows are miscalculated. It also breaks the shapes of spotlights etc.
image
image

I made some modification to fix the issue,
main...tjwei:terminaltexteffects:main
It use unicodedata.east_asian_width(x) in ['W', 'F'] to determine whether a character is wide or not.
This is just a quick workaround for explaining the issue, and I believe there are many I am not aware of.
There are also issues related to each effect, like for waves or decrypt, the gradient or replacement characters should also be 2 columns wide for wide characters. synthgrid also needs some adjustment. Some effect may not even make much sense when considering some characters are two columns wide.

Update:
synthgrid seems fine after I fixed my code. I failed to handle the situation that two current_character_visual may have same position.

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

No branches or pull requests

1 participant