cli-table / cli-table3

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

table overflows and wraps screen even with word wrapping enabled #351

Closed benmccann closed 3 months ago

benmccann commented 3 months ago

The table isn't being fit to my screen even when word wrapping is on

Screenshot from 2024-06-23 14-35-00

Code to reproduce:

var Table = require('cli-table3');

// instantiate
var table = new Table({
    wordWrap: true,
    head: ['TH 1 label', 'TH 2 label'],
    colWidths: [100, 200]
});

// table is an Array, so you can `push`, `unshift`, `splice` and friends
table.push(
    ['First value First value First value First value First value First value First value First value First value First value First value First value First value First value First value First value First value First value', 'Second value']
  , ['First value', 'Second value']
);

console.log(table.toString());

related https://github.com/cli-table/cli-table3/issues/57

speedytwenty commented 3 months ago

For brevity, I'm going to dismiss this on the grounds that it is outside the scope of cli-table3.

That's not to say there isn't an easy solution for your use case. Decisions like these should bel left to the implementors of cli-table3.

Keyword "tput" may put you in a useful direction: https://stackoverflow.com/a/263900

By all means, anyone should feel free to share their implementation(s) appropriately!

speedytwenty commented 3 months ago

Based on your edit and the screenshot, the width of the table (300) is more than the screen width. You're inducing the terminal's own text-wrapping by exceeding the width of the screen.