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

Some graphemes (e.g. country flags) break the truncation invariant #24

Open
erictheswift opened this issue Jan 10, 2024 · 1 comment
Open

Comments

@erictheswift
Copy link

erictheswift commented Jan 10, 2024

Considering cli-truncate works with terminal char widths, I think this expectation is valid:
expect(cliTruncate('🇪🇺!', 2)).toEqual('…')

However due to country flags consisting of multiple code points treated as separate chars in slice-ansi, cliTruncate returns "🇪…"

This is not only rendering artifact but a broken invariant, e.g. string-width stringWidth("🇪…") returns 3 that is above requested width 2.

using Intl.Segmenter in slice-ansi can be possible way to fix it: chalk/slice-ansi#35

Got here debugging ink truncation issue when line had country flag on box wrap edge)

@erictheswift erictheswift changed the title Country flags consisting of multiple codepoints are being exploded Graphemes consisting of multiple codepoints break the truncation invariant Jan 10, 2024
@erictheswift erictheswift changed the title Graphemes consisting of multiple codepoints break the truncation invariant Some graphemes (e.g. country flags) break the truncation invariant Jan 10, 2024
@erictheswift
Copy link
Author

Also:
require('string-width').default(require('cli-truncate').default('🔀!',2)) // 3

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

1 participant