Skip to content

Instantly share code, notes, and snippets.

@theohogberg
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theohogberg/bb86c4665a08ff856c80 to your computer and use it in GitHub Desktop.
Save theohogberg/bb86c4665a08ff856c80 to your computer and use it in GitHub Desktop.
get node terminal width and height
function termRect () {
var tty = require('tty');
var width;
var height;
if(tty.isatty(1) && tty.isatty(2)) {
if(process.stdout.getWindowSize) {
width = process.stdout.getWindowSize(1)[0];
height = process.stdout.getWindowSize(1)[1];
} else if (tty.getWindowSize) {
width = tty.getWindowSize()[1];
height = tty.getWindowSize()[0];
} else if (process.stdout.columns && process.stdout.rows) {
height = process.stdout.columns;
width = process.stdout.rows;
}
} else {
throw new Error('window-size could not get size with tty or process.stdout.');
}
return {'height':height, 'width':width};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment