Skip to content

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

Open
@erictheswift

Description

@erictheswift

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions