[Pkg-javascript-commits] [node-supports-color] 01/01: Imported Upstream version 3.1.2
Mathias Behrle
mbehrle at moszumanska.debian.org
Sat Jul 23 13:43:33 UTC 2016
This is an automated email from the git hooks/post-receive script.
mbehrle pushed a commit to branch upstream
in repository node-supports-color.
commit 0ee0052822c7842b2f16dc5b6e1797b19ae89bcc
Author: Mathias Behrle <mathiasb at m9s.biz>
Date: Wed Jul 13 17:53:18 2016 +0200
Imported Upstream version 3.1.2
---
.editorconfig | 2 +-
.jshintrc | 13 ---------
.travis.yml | 2 ++
browser.js | 2 ++
cli.js | 29 ------------------
index.js | 67 ++++++++++++++++++++++++++++++------------
package.json | 35 ++++++++++++++--------
readme.md | 40 ++++++++++++++++---------
test.js | 94 +++++++++++++++++++++++++++++++++++++++++++++++++----------
9 files changed, 182 insertions(+), 102 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 86c8f59..8f9d77e 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,7 +7,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
-[package.json]
+[{package.json,*.yml}]
indent_style = space
indent_size = 2
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 804f8af..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "node": true,
- "esnext": true,
- "bitwise": true,
- "camelcase": true,
- "curly": true,
- "immed": true,
- "newcap": true,
- "noarg": true,
- "undef": true,
- "unused": "vars",
- "strict": true
-}
diff --git a/.travis.yml b/.travis.yml
index ccde138..bf55bd6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,3 +7,5 @@ node_js:
- '0.8'
before_install:
- npm install -g npm
+script:
+ - npm run travis
diff --git a/browser.js b/browser.js
new file mode 100644
index 0000000..ae7c87b
--- /dev/null
+++ b/browser.js
@@ -0,0 +1,2 @@
+'use strict';
+module.exports = false;
diff --git a/cli.js b/cli.js
deleted file mode 100755
index e746987..0000000
--- a/cli.js
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env node
-'use strict';
-var pkg = require('./package.json');
-var supportsColor = require('./');
-var argv = process.argv.slice(2);
-
-function help() {
- console.log([
- '',
- ' ' + pkg.description,
- '',
- ' Usage',
- ' supports-color',
- '',
- ' Exits with code 0 if color is supported and 1 if not'
- ].join('\n'));
-}
-
-if (argv.indexOf('--help') !== -1) {
- help();
- return;
-}
-
-if (argv.indexOf('--version') !== -1) {
- console.log(pkg.version);
- return;
-}
-
-process.exit(supportsColor ? 0 : 1);
diff --git a/index.js b/index.js
index a171964..113040d 100644
--- a/index.js
+++ b/index.js
@@ -1,43 +1,72 @@
'use strict';
-var argv = process.argv;
+var hasFlag = require('has-flag');
-module.exports = (function () {
- if ('FORCE_COLOR' in process.env) {
- return true;
+var support = function (level) {
+ if (level === 0) {
+ return false;
}
- if (argv.indexOf('--no-color') !== -1 ||
- argv.indexOf('--no-colors') !== -1 ||
- argv.indexOf('--color=false') !== -1) {
- return false;
+ return {
+ level: level,
+ hasBasic: true,
+ has256: level >= 2,
+ has16m: level >= 3
+ };
+};
+
+var supportLevel = (function () {
+ if (hasFlag('no-color') ||
+ hasFlag('no-colors') ||
+ hasFlag('color=false')) {
+ return 0;
+ }
+
+ if (hasFlag('color=16m') ||
+ hasFlag('color=full') ||
+ hasFlag('color=truecolor')) {
+ return 3;
+ }
+
+ if (hasFlag('color=256')) {
+ return 2;
}
- if (argv.indexOf('--color') !== -1 ||
- argv.indexOf('--colors') !== -1 ||
- argv.indexOf('--color=true') !== -1 ||
- argv.indexOf('--color=always') !== -1) {
- return true;
+ if (hasFlag('color') ||
+ hasFlag('colors') ||
+ hasFlag('color=true') ||
+ hasFlag('color=always')) {
+ return 1;
}
if (process.stdout && !process.stdout.isTTY) {
- return false;
+ return 0;
}
if (process.platform === 'win32') {
- return true;
+ return 1;
}
if ('COLORTERM' in process.env) {
- return true;
+ return 1;
}
if (process.env.TERM === 'dumb') {
- return false;
+ return 0;
+ }
+
+ if (/^xterm-256(?:color)?/.test(process.env.TERM)) {
+ return 2;
}
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) {
- return true;
+ return 1;
}
- return false;
+ return 0;
})();
+
+if (supportLevel === 0 && 'FORCE_COLOR' in process.env) {
+ supportLevel = 1;
+}
+
+module.exports = process && support(supportLevel);
diff --git a/package.json b/package.json
index 7c808ea..0f08cb9 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,9 @@
{
"name": "supports-color",
- "version": "1.3.1",
+ "version": "3.1.2",
"description": "Detect whether a terminal supports color",
"license": "MIT",
- "repository": "sindresorhus/supports-color",
+ "repository": "chalk/supports-color",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus at gmail.com",
@@ -11,24 +11,22 @@
},
"maintainers": [
"Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)",
- "Joshua Appelman <jappelman at xebia.com> (jbnicolai.com)"
+ "Joshua Appelman <jappelman at xebia.com> (jbnicolai.com)",
+ "JD Ballard <i.am.qix at gmail.com> (github.com/qix-)"
],
- "bin": {
- "supports-color": "cli.js"
- },
+ "browser": "browser.js",
"engines": {
"node": ">=0.8.0"
},
"scripts": {
- "test": "mocha"
+ "test": "xo && mocha",
+ "travis": "mocha"
},
"files": [
"index.js",
- "cli.js"
+ "browser.js"
],
"keywords": [
- "cli",
- "bin",
"color",
"colour",
"colors",
@@ -46,10 +44,23 @@
"support",
"supports",
"capability",
- "detect"
+ "detect",
+ "truecolor",
+ "16m",
+ "million"
],
+ "dependencies": {
+ "has-flag": "^1.0.0"
+ },
"devDependencies": {
"mocha": "*",
- "require-uncached": "^1.0.2"
+ "require-uncached": "^1.0.2",
+ "xo": "*"
+ },
+ "xo": {
+ "envs": [
+ "node",
+ "mocha"
+ ]
}
}
diff --git a/readme.md b/readme.md
index fe6016f..f7bae4c 100644
--- a/readme.md
+++ b/readme.md
@@ -1,4 +1,4 @@
-# supports-color [![Build Status](https://travis-ci.org/sindresorhus/supports-color.svg?branch=master)](https://travis-ci.org/sindresorhus/supports-color)
+# supports-color [![Build Status](https://travis-ci.org/chalk/supports-color.svg?branch=master)](https://travis-ci.org/chalk/supports-color)
> Detect whether a terminal supports color
@@ -18,27 +18,41 @@ var supportsColor = require('supports-color');
if (supportsColor) {
console.log('Terminal supports color');
}
+
+if (supportsColor.has256) {
+ console.log('Terminal supports 256 colors');
+}
+
+if (supportsColor.has16m) {
+ console.log('Terminal supports 16 million colors (truecolor)');
+}
```
-It obeys the `--color` and `--no-color` CLI flags.
-For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR` with any value to force color. Trumps `--no-color`.
+## API
+Returns an `object`, or `false` if color is not supported.
-## CLI
+The returned object specifies a level of support for color through a `.level` property and a corresponding flag:
-```
-$ npm install --global supports-color
-```
+- `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
+- `.level = 2` and `.has256 = true`: 256 color support
+- `.level = 3` and `.has16m = true`: 16 million (truecolor) support
-```
-$ supports-color --help
- Usage
- supports-color
+## Info
- Exits with code 0 if color is supported and 1 if not
-```
+It obeys the `--color` and `--no-color` CLI flags.
+
+For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR` with any value to force color. Trumps `--no-color`.
+
+Explicit 256/truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
+
+
+## Related
+
+- [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
+- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
## License
diff --git a/test.js b/test.js
index ec6ad4b..034b8bb 100644
--- a/test.js
+++ b/test.js
@@ -10,55 +10,119 @@ beforeEach(function () {
it('should return true if `FORCE_COLOR` is in env', function () {
process.env.FORCE_COLOR = true;
- assert.equal(requireUncached('./'), true);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
+ assert.equal(result.level, 1);
});
it('should return false if not TTY', function () {
process.stdout.isTTY = false;
- assert.equal(requireUncached('./'), false);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), false);
});
it('should return false if --no-color flag is used', function () {
+ process.env = {TERM: 'xterm-256color'};
process.argv = ['--no-color'];
- assert.equal(requireUncached('./'), false);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), false);
});
it('should return false if --no-colors flag is used', function () {
+ process.env = {TERM: 'xterm-256color'};
process.argv = ['--no-colors'];
- assert.equal(requireUncached('./'), false);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), false);
});
it('should return true if --color flag is used', function () {
process.argv = ['--color'];
- assert.equal(requireUncached('./'), true);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
});
it('should return true if --colors flag is used', function () {
process.argv = ['--colors'];
- assert.equal(requireUncached('./'), true);
-});
-
-it('should return false if `UPSTART_JOB` is in env', function () {
- process.env.UPSTART_JOB = true;
- assert.equal(requireUncached('./'), false);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
});
it('should return true if `COLORTERM` is in env', function () {
process.env.COLORTERM = true;
- assert.equal(requireUncached('./'), true);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
});
it('should support `--color=true` flag', function () {
process.argv = ['--color=true'];
- assert.equal(requireUncached('./'), true);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
});
it('should support `--color=always` flag', function () {
process.argv = ['--color=always'];
- assert.equal(requireUncached('./'), true);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
});
it('should support `--color=false` flag', function () {
+ process.env = {TERM: 'xterm-256color'};
process.argv = ['--color=false'];
- assert.equal(requireUncached('./'), false);
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), false);
+});
+
+it('should support `--color=256` flag', function () {
+ process.argv = ['--color=256'];
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
+});
+
+it('level should be 2 if `--color=256` flag is used', function () {
+ process.argv = ['--color=256'];
+ var result = requireUncached('./');
+ assert.equal(result.level, 2);
+ assert.equal(result.has256, true);
+});
+
+it('should support `--color=16m` flag', function () {
+ process.argv = ['--color=16m'];
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
+});
+
+it('should support `--color=full` flag', function () {
+ process.argv = ['--color=full'];
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
+});
+
+it('should support `--color=truecolor` flag', function () {
+ process.argv = ['--color=truecolor'];
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
+});
+
+it('level should be 3 if `--color=16m` flag is used', function () {
+ process.argv = ['--color=16m'];
+ var result = requireUncached('./');
+ assert.equal(result.level, 3);
+ assert.equal(result.has256, true);
+ assert.equal(result.has16m, true);
+});
+
+it('should ignore post-terminator flags', function () {
+ process.argv = ['--color', '--', '--no-color'];
+ var result = requireUncached('./');
+ assert.equal(Boolean(result), true);
+});
+
+it('should allow tests of the properties on false', function () {
+ process.env = {TERM: 'xterm-256color'};
+ process.argv = ['--no-color'];
+ var result = requireUncached('./');
+ assert.equal(Boolean(result.hasBasic), false);
+ assert.equal(Boolean(result.has256), false);
+ assert.equal(Boolean(result.has16m), false);
+ assert.equal(result.level > 0, false);
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-supports-color.git
More information about the Pkg-javascript-commits
mailing list