Open mknj opened 3 years ago
The function stringWidth from "string-with" reports the correct width of strings, but strlen from "printable-characters" does not.
import p from 'printable-characters'
import a from 'as-table'
import stringWidth from 'string-width'
const asTable=a.configure({delimiter:" | "})
const d=[
{ string: 'abcde', num: "ok" },
{ string: 'ᄍ', num: "ok" },
{ string: '無', num: "bad" },
{ string: '🕑', num: "bad" },
{ string: '💩', num: "bad" },
{ string: '⬢', num: "ok" },
]
for(const e of d) {
e.stringWidth=stringWidth(e.string)
e.strlen=p.strlen(e.string)
}
console.log(asTable (d) )
string | num | stringWidth | strlen
-----------------------------------
abcde | ok | 5 | 5
ᄍ | ok | 1 | 1
無 | bad | 2 | 1
🕑 | bad | 2 | 1
💩 | bad | 2 | 1
⬢ | ok | 1 | 1
Thanks for the report. Seems that emoji rendering is terminal-dependent, sometimes it's double width, sometimes single width...
And in VSCode it's somehow 1.5-width:
It also seems that now most terminals render it as double width (several years ago it was different), so we probably need to change printable-characters to account for that.
Problem
Tables with double width unicode characters are not correctly aligned (see screenshot).
observed output
sidenote
The vi Editor in the same terminal window can handles these characters correctly. (the cursor does not jump left/right when going up/down on lines that contain such characters)
versions
example program