How wide is the node.js console?

后端 未结 2 1083
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 23:41

In node.js, how do I get the current width of the console window and/or buffer?

The analog in .net is Console.BufferWidth and/or Console.WindowWidth.

I want

相关标签:
2条回答
  • 2020-12-30 00:05
    if (process.stdout.isTTY) {
      console.log("The console size is:", process.stdout.getWindowSize());
    } else {
      console.log("stdout is not a console");
    } 
    
    0 讨论(0)
  • Looks like the current best way is this property:

    process.stdout.columns
    

    And for height (rows):

    process.stdout.rows
    

    Also note that there is a "resize" event, which might come in handy:

    process.stdout.on('resize', function() {
      console.log('screen size has changed!');
      console.log(process.stdout.columns + 'x' + process.stdout.rows);
    });
    

    Documentation here: http://nodejs.org/api/tty.html#tty_tty

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