Get width of terminal in Node.js

后端 未结 1 479
小鲜肉
小鲜肉 2021-02-05 00:22
console.log(process.env.COLUMNS)

Yields undefined, although,

$ echo $COLUMNS

Outputs as expected:

<
相关标签:
1条回答
  • 2021-02-05 01:01
    console.log('Terminal size: ' + process.stdout.columns + 'x' + process.stdout.rows);
    

    And the output looks like e.g. "Terminal size: 80x24". There is also an event if the console size changes.

    It's explained under tty in the docs.

    0 讨论(0)
提交回复
热议问题