cli-table / cli-table3

Pretty unicode tables for the command line
MIT License
535 stars 44 forks source link

Erroneous truncated columns when using colSpan #289

Closed speedytwenty closed 2 years ago

speedytwenty commented 2 years ago

If an entire column contains cells with a colWidth > 1, they don't get a proper width calculation (when colWidths aren't specified).

This can occur in different circumstances.

const Table = require('.');

const table = new Table({ debug: 3 });
table.push([{ colSpan: 2, content: 'I should not be truncated' }]);
console.log(table.toString());

Expected:

┌────────────────────────────┐
│ I should not be truncated  │
└────────────────────────────┘

Current behavior:

┌───┐
│ … │
└───┘

If a cell above has colSpan, no width is passed down, and a cell below might be truncated when it doesn't need to be. Eg.

const Table = require('.');
const table = new Table();
table.push(
  [{ content: '0-0 (1x3)', colSpan: 3, rowSpan: 1 }],
  [
    { content: '1-0 (2x2)', colSpan: 2, rowSpan: 2 },
    { content: '1-2 (2x1)', colSpan: 1, rowSpan: 2 },
  ],
  []
);
console.log(table.toString());

Expected:

┌────────────────────────┐
│ 0-0 (1x3)              │
├────────────┬───────────┤
│ 1-0 (2x2)  │ 1-2 (2x1) │
│            │           │
│            │           │
└────────────┴───────────┘

Current behavior:

┌───────────────┐
│ 0-0 (1x3)     │
├───┬───────────┤
│ … │ 1-2 (2x1) │
│   │           │
│   │           │
└───┴───────────┘