Closed manuelF closed 4 months ago
Note that the fix provided in PR#118 (after being modified to include both sets of chars) displays correctly. https://github.com/bczsalba/pytermgui/pull/118
RE_CHINESE = re.compile(r"[\u4e00-\u9fff]")
RE_EMOJI = re.compile(r"[\u2000-\u2fff]")
[...]
@lru_cache(maxsize=None)
def real_length(text: str) -> int:
if bool(RE_CHINESE.search(text)) or bool(RE_EMOJI.search(text)):
return sum(wcswidth(c) for c in strip_ansi(text))
return len(strip_ansi(text))
Describe the bug Using emojis (on terminals that support it) misaligns the windows due to wrong length computed (byte length vs rune length)
To Reproduce
Taking emojis from the https://en.wikipedia.org/wiki/X_mark:
Expected behavior A normal outer box.
**Seen behaviour*** Boxes with emojis on the line are offset, due to printing chars differently.
System information
Possible cause Possible incorrect way of computing
real_length
with wide-characters.https://github.com/bczsalba/pytermgui/blob/56b2cc1dc74ada438088719d2ebe95e21d509ad6/pytermgui/widgets/base.py#L781
Possible solution See alternatives like: https://stackoverflow.com/a/30775818
Maybe?
Thanks!