Last active
August 29, 2015 14:23
-
-
Save theohogberg/bb86c4665a08ff856c80 to your computer and use it in GitHub Desktop.
get node terminal width and height
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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