c4spar / deno-cliffy

Command line framework for deno πŸ¦• Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...

Home Page:https://cliffy.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Table layout broken for various types of Unicode characters

lionel-rowe opened this issue Β· comments

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:

image

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 𐌰𐌱).