Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to expand one column to fill console #124

Open
floratmin opened this issue Oct 16, 2020 · 0 comments
Open

Add option to expand one column to fill console #124

floratmin opened this issue Oct 16, 2020 · 0 comments
Assignees

Comments

@floratmin
Copy link

In node I can get the width of the console from process.stdout.columns. So I can get the available rest width for one column with the following formula:

const fixedColumnsWidth = [ w1, w2, ..., wn-1];
const fixedColumnsCount = fixedColumnsWidth.length; // n - 1
const consoleWidth = process.stdout.columns; // Other environments could not have process
// calculate width of column n
const wn = consoleWidth
    - fixedColumnsWidth.reduce((sum, width) => sum + width, 0) // get the sum of all fixed column widths
    - (fixedColumnsCount + 1) * 3 // add 1 for the variable width column, each column has three extra chars
    - 1;  // subtract one char for the first vertical line

I have only to make sure that wn does not get smaller than zero. So we should also define a minWidth for this column. I am using this on my tables with the help of a little manual calculation and a ternary expression.

@nam-hle nam-hle self-assigned this May 15, 2021
@nam-hle nam-hle linked a pull request May 15, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants