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 to exercise more control over my line wrapping.
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
if (process.stdout.isTTY) {
console.log("The console size is:", process.stdout.getWindowSize());
} else {
console.log("stdout is not a console");
}