index.js 573 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. exports = module.exports = cliWidth;
  3. exports.defaultWidth = 0;
  4. function cliWidth() {
  5. if (process.stdout.getWindowSize) {
  6. return process.stdout.getWindowSize()[0] || exports.defaultWidth;
  7. }
  8. else {
  9. var tty = require('tty');
  10. if (tty.getWindowSize) {
  11. return tty.getWindowSize()[1] || exports.defaultWidth;
  12. }
  13. else {
  14. if (process.env.CLI_WIDTH) {
  15. var width = parseInt(process.env.CLI_WIDTH, 10);
  16. if (!isNaN(width)) {
  17. return width;
  18. }
  19. }
  20. return exports.defaultWidth;
  21. }
  22. }
  23. };