sindresorhus / cli-truncate

Truncate a string to a specific width in the terminal
MIT License
85 stars 14 forks source link

Support fullwidth characters and unicode surrogate pairs #1

Closed sindresorhus closed 7 years ago

sindresorhus commented 8 years ago

https://github.com/sindresorhus/cli-truncate/blob/dbc522d6f3c1fd7b287b39521ed73a7c9e98fd66/test.js#L15-L17

Depends on https://github.com/chalk/wrap-ansi/issues/10 and https://github.com/chalk/wrap-ansi/issues/11.

Note to self: Update the readme description when this is fixed.

kevva commented 7 years ago

Is this test correct https://github.com/sindresorhus/cli-truncate/blob/dbc522d6f3c1fd7b287b39521ed73a7c9e98fd66/test.js#L16? We're testing the opposite in slice-ansi https://github.com/chalk/slice-ansi/blob/master/test.js#L46. The surrogate pairs are counted as a single character and not two.

The fullwidth character test works with the new version of slice-ansi though.

sindresorhus commented 7 years ago

Is this test correct /test.js@dbc522d#L16?

No, I don't think it's correct.

kevva commented 7 years ago

Nah, me neither. The visual width should only be one character. Will supply a PR with a bump of slice-ansi and fixed tests.