Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1023B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. exports = module.exports = cliWidth;
  3. function normalizeOpts(options) {
  4. var defaultOpts = {
  5. defaultWidth: 0,
  6. output: process.stdout,
  7. tty: require('tty')
  8. };
  9. if (!options) {
  10. return defaultOpts;
  11. } else {
  12. Object.keys(defaultOpts).forEach(function (key) {
  13. if (!options[key]) {
  14. options[key] = defaultOpts[key];
  15. }
  16. });
  17. return options;
  18. }
  19. }
  20. function cliWidth(options) {
  21. var opts = normalizeOpts(options);
  22. if (opts.output.getWindowSize) {
  23. return opts.output.getWindowSize()[0] || opts.defaultWidth;
  24. } else {
  25. if (opts.tty.getWindowSize) {
  26. return opts.tty.getWindowSize()[1] || opts.defaultWidth;
  27. } else {
  28. if (opts.output.columns) {
  29. return opts.output.columns;
  30. } else {
  31. if (process.env.CLI_WIDTH) {
  32. var width = parseInt(process.env.CLI_WIDTH, 10);
  33. if (!isNaN(width) && width !== 0) {
  34. return width;
  35. }
  36. }
  37. }
  38. return opts.defaultWidth;
  39. }
  40. }
  41. };