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

Extend display_width to handle emojis when unicode-width is disabled #276

Merged
merged 1 commit into from
Jan 3, 2021

Conversation

mgeisler
Copy link
Owner

@mgeisler mgeisler commented Jan 3, 2021

The unicode-width Cargo feature is used by default to measure the width of the characters. Without it, we used to fall back to a simple model where each character is has a width of one column.

However, this is wrong for emojis such as “😂”, which normally take up two columns when printed in a terminal. We now handle such characters as well — we simply assume that all characters above U+1100 is a double-width character.

This turns out to be correct for emojis, but it is wrong for many non-emoji characters. To handle those, the unicode-width feature should simply be enabled.

The unicode-width Cargo feature is used by default to measure the
width of the characters. Without it, we used to fall back to a simple
model where each character is has a width of one column.

However, this is wrong for emojis such as “😂”, which normally take up
two columns when printed in a terminal. We now handle such characters
as well — we simply assume that all characters above U+1100 is a
double-width character.

This turns out to be correct for emojis, but it is wrong for many
non-emoji characters. To handle those, the unicode-width feature
should simply be enabled.
@mgeisler mgeisler merged commit 0d19a02 into master Jan 3, 2021
@mgeisler mgeisler deleted the handle-emojis-in-str-width branch January 30, 2021 16:46
@github-actions github-actions bot mentioned this pull request Feb 20, 2021
@mgeisler mgeisler changed the title Extend display_width to handle emojis when unicode-width is disabled Extend display_width to handle emojis when unicode-width is disabled Jan 15, 2022
mgeisler added a commit that referenced this pull request Jan 15, 2022
After #276, the `display_width` function can handle a limited set of
non-ASCII characters. This is enough to make these tests pass both
with and without the `unicode-width` Cargo feature.
mgeisler added a commit that referenced this pull request Jan 16, 2022
After #276, the `display_width` function can handle a limited set of
non-ASCII characters. This is enough to make these tests pass both
with and without the `unicode-width` Cargo feature.
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

Successfully merging this pull request may close these issues.

1 participant