gajus / table

Formats data into a string table.
Other
886 stars 77 forks source link

Emoji break wrapWord #180

Open awensaunders opened 2 years ago

awensaunders commented 2 years ago

Hi there,

If I enable word wrap with columns that have emoji in them, it eats the first letter of the word on the line below... I assume this has something to do with full width calculations.

Example

const table = require("table");

const works = [
  ["Name", "Number"],
  ["Some Text", 24],
  ["Some more text", 22],
  ["I am a reallylong name", 19],
  ["I have a super duperlongname", 18],
];
const doesntwork = [
  ["Name", "Number"],
  ["๐Ÿฅ‡ Some Text", 24],
  ["๐Ÿฅˆ Some more text", 22],
  ["๐Ÿฅ‰ I am a reallylong name", 19],
  ["I have a super duperlongname", 18],
];

const config = {
  columns: [
    { alignment: "left", width: 15, wrapWord: true },
    { alignment: "right", width: 10, wrapWord: true },
  ],
  header: { alignment: "center", content: "My Table", wrapWord: true },
};
console.log(table.table(works, config));
console.log(table.table(doesntwork, config));

Results

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘           My Table           โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ Name            โ”‚     Number โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ Some Text       โ”‚         24 โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ Some more text  โ”‚         22 โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ I am a          โ”‚         19 โ•‘
โ•‘ reallylong name โ”‚            โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ I have a super  โ”‚         18 โ•‘
โ•‘ duperlongname   โ”‚            โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘           My Table           โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ Name            โ”‚     Number โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ ๐Ÿฅ‡ Some Text    โ”‚         24 โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ ๐Ÿฅˆ Some more    โ”‚         22 โ•‘
โ•‘ ext             โ”‚            โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ ๐Ÿฅ‰ I am a       โ”‚         19 โ•‘
โ•‘ eallylong name  โ”‚            โ•‘
โ•Ÿโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ข
โ•‘ I have a super  โ”‚         18 โ•‘
โ•‘ duperlongname   โ”‚            โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•งโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

Do you have any idea how to remedy this?

Thanks for making this library. It's of great use to me :smile:

nam-hle commented 2 years ago

Hi @awensaunders, I tested the output on MacOs and it works fine in various applications: the native terminal, iTerm2, and Intellij IDEA terminal. Can you provide some information about your working environment?

fullgream commented 2 years ago

I have a similar issue when I save a table in a txt file

nam-hle commented 2 years ago

The library is expected to run and display in monospace output like the terminal. Is it still out of sync if you change to a monospace font?

gaboroa14 commented 1 year ago

Tried a monospace font while dumping the text on a node-canvas and it stills breaks the wrapping, although just a little bit.