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

Great for πŸ¦„ but it hates πŸ³οΈβ€πŸŒˆ :) #53

Open
ckir opened this issue Jan 7, 2024 · 5 comments
Open

Great for πŸ¦„ but it hates πŸ³οΈβ€πŸŒˆ :) #53

ckir opened this issue Jan 7, 2024 · 5 comments

Comments

@ckir
Copy link

ckir commented Jan 7, 2024

When the input string contains characters like '1f3f3-fe0f-200d-1f308', // rainbow flag πŸ³οΈβ€πŸŒˆ the width is wrong.

@sindresorhus
Copy link
Owner

How is it wrong?

@ckir
Copy link
Author

ckir commented Jan 8, 2024

import stringWidth from 'string-width'

const ruler1 = '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456'
const str1 = 'The quick πŸ³οΈβ€πŸŒˆ πŸ¦„ 🎠 🐴 🐎 ❀ ✨ 🌈 πŸŒ·πŸŽπŸ’©\u001b[100m πŸ˜œπŸ‘πŸ³οΈβ€πŸŒˆ brown \u001b[49m\u001b[31mfox jumped over \u001b[39mthe lazy \u001b[32mdog and then\u001b[39m\u001b[101m ran away with the unicorn. πŸ’› \u001b[49m'
console.log(ruler1)
console.log(str1)
console.log(ruler1.length, stringWidth(str1))

const ruler2 = '01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345'
const str2 = 'The quick πŸ¦„ 🎠 🐴 🐎 ❀ ✨ 🌈 πŸŒ·πŸŽπŸ’©\u001b[100m πŸ˜œπŸ‘ brown \u001b[49m\u001b[31mfox jumped over \u001b[39mthe lazy \u001b[32mdog and then\u001b[39m\u001b[101m ran away with the unicorn. πŸ’› \u001b[49m'
console.log(ruler2)
console.log(str2)
console.log(ruler2.length, stringWidth(str2))

It gives this at least on my windows terminal
StringWidth

@sindresorhus
Copy link
Owner

I was looking for an explanation, not example, on how it's wrong. It's not clear from the example either what the exact problem is.

@sindresorhus
Copy link
Owner

This is what it looks like in iTerm.

Screenshot 2024-01-08 at 14 44 56

@ckir
Copy link
Author

ckir commented Jan 8, 2024

I'm very sorry. Never meant to confuse you. As I read the package description is: Get the visual width of a string - the number of columns required to display it. To me at least that means I need the "size of the ruler" columns to print it. So the answers I expected was 127 and 116. In my case I was trying to print the string in a box and the difference in size caused the right side of the box to break. As far I concern I have already implemented an adjustment so I'm fine. I liked to know that the results are different in iTerm.

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

2 participants