-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Introduce Bun.stringWidth
#8327
Conversation
❌ @Jarred-Sumner 3 files with test failures on bun-darwin-aarch64: |
❌ @Jarred-Sumner 4 files with test failures on linux-x64: |
❌ @Jarred-Sumner 4 files with test failures on linux-x64-baseline: |
❌ @Jarred-Sumner 5 files with test failures on bun-darwin-x64:
|
This is not a trivial problem, I would be careful taking on the maintenance burden. Looking at the implementation, I think the most important things are correct (also very nice fast implementation), although I'm not entirely sure how a character knows to be width zero after following a zero-width join. I'm sure you've looked at a lot of resources already, but https://www.jeffquast.com/post/ucs-detect-test-results/ is a good article on the difficulty of the problem. It includes some specific examples that I recommend adding to the tests. Of course there is also the problem of width changing over time for Unicode versions, so what is actually displayed might differ by device. |
We're mostly aiming to match the behavior of the |
Merging because I'd like to get this in the release and it feels pretty safe to do so. |
❌🪟 @Jarred-Sumner, there are 10 test regressions on Windows x86_64
|
* Introduce `Bun.stringWidth` * [autofix.ci] apply automated fixes * Update utils.md --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
What does this PR do?
This fixes an issue where console.table would not align text properly when the input contains ANSII escape sequences.
This also introduces
Bun.stringWidth
, which has nearly the same API as the extremely popularstring-width
npm package (> 100 million weekly downloads) except this implementation is roughly 490x faster compared to running string-width in node.Fixes #8155
How did you verify your code works?
There are some tests