columnify icon indicating copy to clipboard operation
columnify copied to clipboard

padding is not based on the true length (wcwidth) of paddingChr

Open danyshaanan opened this issue 11 years ago • 4 comments

For instance, { paddingChr: chalk.gray('.') } will break format.

Problem is within utils.js::repeatString which uses slice.

danyshaanan avatar Aug 11 '14 19:08 danyshaanan

Good call.

timoxley avatar Aug 12 '14 00:08 timoxley

@timoxley : when wcwidth(str)===1, (like with chalk.gray('.')) droping the slice(0,len) solves it (relevant line), but when wcwidth(str)>1 it's not always possible to multiply it several times to get the required length, and it is required to trim the last occurrence. Any idea how to properly trim such a string?

i.e. How can I slice the first two visual chars of chalk.gray('123') without messing the colors?

danyshaanan avatar Aug 12 '14 06:08 danyshaanan

I think the only way to do this would be to pass it through something like sindresorhus/strip-ansi first.

timoxley avatar Aug 18 '14 11:08 timoxley

That would enable slicing out the actual wanted length, but is there any reasonable way to colour it again before concatenating to the padding?

I'm starting to think that there is no way to do this, meaning we should disallow wcwidth(padding) > 1, wcwidth(padding) !== padding.length), or preferably, the combination of the two.

danyshaanan avatar Aug 18 '14 12:08 danyshaanan