Width
Control the column width.
When dealing with large values or texts, you can set a fixed column (max-)width to force line breaks. By default each column width depends on the largest value in it. Or you can make the columns fill all the terminal's width.
width
Using the width option you can set a fixed numeric one, auto or stretch.
fixed
In this case, all columns have the same fixed width.
import { Table } from 'voici.js'
const data = [
{
small: 'Lorem ipsum dolor sit amet',
medium:
'At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet',
large:
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
},
{
small: 'Lorem ipsum dolor sit amet',
medium:
'At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet',
large:
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
}
];
const config = {
header: {
width: 20
}
};
const table = new Table(data, config);
table.printPlain();Output:
auto
Using auto, the default value, every column uses as much space as needed. The size is based on the cells' content length.
stretch
By setting stretch, the entire terminal width is used. The percentage share remains the same and is based on the cells' content.
maxWidth
Using the maxWidth option you can set a fixed maximum width that is applied for each column. In this case, columns that do not fill the entire space have auto width based on their cells' content.
Output:
Last updated
Was this helpful?