summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/cli-width/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/node_modules/cli-width/index.js')
-rw-r--r--tools/eslint/node_modules/cli-width/index.js47
1 files changed, 34 insertions, 13 deletions
diff --git a/tools/eslint/node_modules/cli-width/index.js b/tools/eslint/node_modules/cli-width/index.js
index f158f362be..70f63e2a2d 100644
--- a/tools/eslint/node_modules/cli-width/index.js
+++ b/tools/eslint/node_modules/cli-width/index.js
@@ -1,28 +1,49 @@
'use strict';
exports = module.exports = cliWidth;
-exports.defaultWidth = 0;
-function cliWidth() {
- if (process.stdout.getWindowSize) {
- return process.stdout.getWindowSize()[0];
+function normalizeOpts(options) {
+ var defaultOpts = {
+ defaultWidth: 0,
+ output: process.stdout,
+ tty: require('tty')
+ };
+ if (!options) {
+ return defaultOpts;
+ } else {
+ Object.keys(defaultOpts).forEach(function (key) {
+ if (!options[key]) {
+ options[key] = defaultOpts[key];
+ }
+ });
+ return options;
}
- else {
- var tty = require('tty');
+}
- if (tty.getWindowSize) {
- return tty.getWindowSize()[1];
+function cliWidth(options) {
+ var opts = normalizeOpts(options);
+ if (opts.output.getWindowSize) {
+ return opts.output.getWindowSize()[0] || opts.defaultWidth;
+ }
+ else {
+ if (opts.tty.getWindowSize) {
+ return opts.tty.getWindowSize()[1] || opts.defaultWidth;
}
else {
- if (process.env.CLI_WIDTH) {
- var width = parseInt(process.env.CLI_WIDTH, 10);
+ if (opts.output.columns) {
+ return opts.output.columns;
+ }
+ else {
+ if (process.env.CLI_WIDTH) {
+ var width = parseInt(process.env.CLI_WIDTH, 10);
- if (!isNaN(width)) {
- return width;
+ if (!isNaN(width)) {
+ return width;
+ }
}
}
- return exports.defaultWidth;
+ return opts.defaultWidth;
}
}
};