index.js 827 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. /*!
  3. * window-size <https://github.com/jonschlinkert/window-size>
  4. *
  5. * Copyright (c) 2014-2015 Jon Schlinkert
  6. * Licensed under the MIT license.
  7. */
  8. var tty = require('tty');
  9. module.exports = (function () {
  10. var width;
  11. var height;
  12. if (tty.isatty(1) && tty.isatty(2)) {
  13. if (process.stdout.getWindowSize) {
  14. width = process.stdout.getWindowSize(1)[0];
  15. height = process.stdout.getWindowSize(1)[1];
  16. } else if (tty.getWindowSize) {
  17. width = tty.getWindowSize()[1];
  18. height = tty.getWindowSize()[0];
  19. } else if (process.stdout.columns && process.stdout.rows) {
  20. height = process.stdout.rows;
  21. width = process.stdout.columns;
  22. }
  23. } else {
  24. Error('window-size could not get size with tty or process.stdout.');
  25. }
  26. return {height: height, width: width};
  27. })();