console-table-printer icon indicating copy to clipboard operation
console-table-printer copied to clipboard

Emoji charLength when combining with text

Open nicojs opened this issue 3 years ago • 2 comments

I don't understand how the charLength works when combined with text.

https://console-table.netlify.app/docs/doc-emojis-special-chars

See this example:

import { Table } from "console-table-printer";

const table = new Table({
  rows: [
    {
      file: "All files",
      "% score": 87.87,
      "✅ killed": 158,
      "⏳ timeout": 4,
      "👽 survived": 15,
      "🙈 no cov": 8,
      "💥 error": 0,
    },
  ],
  charLength: { "⏳": 3, "✅": 2, "👽": 2, "🙈": 2, "💥": 2 },
});

table.printTable();

This outputs:

┌───────────┬─────────┬───────────┬─────────────┬─────────────┬───────────┬──────────┐
│      file │ % score │  ✅ killed │   ⏳ timeout │ 👽 survived │ 🙈 no cov │ 💥 error │
├───────────┼─────────┼───────────┼─────────────┼─────────────┼───────────┼──────────┤
│ All files │   87.87 │       158 │           4 │          15 │         8 │        0 │
└───────────┴─────────┴───────────┴─────────────┴─────────────┴───────────┴──────────┘

But AFAIK I used the correct char lengths for the emojis. What exactly should the value of a charLength be?

nicojs avatar Nov 09 '22 21:11 nicojs

I tried a simple example on multiple editors and it looks like this

158a|
1✅a|

It seems the length of ✅ here is not exactly 2. Its something between 1-2 maybe 1.8 This makes all the calculations harder for console. I need to find a way to add spaces that are less than 1. Only then I will be able to fix this issue

ayonious avatar Nov 10 '22 09:11 ayonious

It seems the length of ✅ here is not exactly 2. Its something between 1-2 maybe 1.8

That seems to be a GH font issue.

To clarify this issue further.

I expect this: image

To be this: image

I don't seem to be able to change the charLength property to accomplish this 🤷‍♀️

nicojs avatar Nov 12 '22 08:11 nicojs