ayonious / console-table-printer

🖥️ 🍭 Printing Pretty Tables on your console
https://console-table.netlify.app
MIT License
172 stars 22 forks source link

Emoji charLength when combining with text #434

Open nicojs opened 1 year ago

nicojs commented 1 year ago

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?

ayonious commented 1 year ago

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

nicojs commented 1 year ago

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 🤷‍♀️