Table layout broken for various types of Unicode characters
lionel-rowe opened this issue Β· comments
lionel-rowe commented
Table layout works correctly for some common categories of double-width Unicode characters, but is still broken for various other types of characters.
import { Table } from "https://deno.land/x/cliffy@v0.25.7/table/mod.ts";
Table.from([
["ab (OK)"],
["π© (OK)"],
["ε (OK)"],
["ν (NOK)"], // Korean
["β (NOK)"], // emoji within BMP
["a\u200cb (NOK)"], // zero-width space
["π°π± (NOK)"], // single-width chars outside of BMP
])
.border(true)
.render();
Output:
Non-BMP emojis are OK, but only by accident, as strLength
iterates over its input using UTF-16 code units rather than Unicode codepoints, and non-BMP characters take up 2 code units. The fact they're double-width is independent of being outside the BMP (counterexamples β emojis within BMP such as β
β; single-width chars outside the BMP such as π°π±).