Skip to content

Some characters do false-positively count as 2 while occupying 1 column in terminal #56

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

Open
erictheswift opened this issue Feb 8, 2024 · 4 comments · May be fixed by #64
Open

Some characters do false-positively count as 2 while occupying 1 column in terminal #56

erictheswift opened this issue Feb 8, 2024 · 4 comments · May be fixed by #64

Comments

@erictheswift
Copy link

erictheswift commented Feb 8, 2024

stringWidth('◼') // 2 in v7, 1 in v5
stringWidth('⚠') // 2 in v7, 1 in v5
stringWidth('✔') // 2 in v7, 1 in v5
(likely not complete list)

seems related to emoji-regex package updates

I guess it is not true that every character considered as emoji due to spec occupies double width. At least at current moment in time.
mathiasbynens/emoji-regex#33

@fabiospampinato
Copy link

fabiospampinato commented Feb 26, 2024

More test cases where this happens, emoji-regex seems indeed potentially buggy:

t.is(stringWidth('\u21a9'), 1);
t.is(stringWidth('\u2194'), 1);
t.is(stringWidth('\u2197'), 1);
t.is(stringWidth('✔'), 1);
t.is(stringWidth('\u2709'), 1);
t.is(stringWidth('\u26a0'), 1);

@unlessgames
Copy link

I get the same issue with for example. Until resolved, one can stick with version ^5.1.2.

@simnalamburt
Copy link

I got the same issue with and in v7 and v6. I'm sticking with v5.1.2 too.

@dmail
Copy link

dmail commented Mar 10, 2025

Is there any solution besides sticking with v5.1.2?

Because version v5.1.2 is causing the following error for me:

Cannot find package 'eastasianwidth' 

(This is because my workspace use both version 7.2.0 and 5.1.2 which NPM fails to properly install apparently)

Update: For now I can fix NPM installation by explicitely adding "eastasianwidth": "^0.2.0", alongside string-width dep:

{
    "string-width": "5.1.2",
    "eastasianwidth": "^0.2.0",
}

dmail added a commit to dmail-fork/string-width that referenced this issue Mar 25, 2025
@dmail dmail linked a pull request Mar 25, 2025 that will close this issue
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 a pull request may close this issue.

5 participants