[Pkg-javascript-commits] [node-supports-color] 01/03: Imported Upstream version 0.2.0
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jun 29 22:24:36 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to branch master
in repository node-supports-color.
commit 751179c4bf0b51adb86ed55a1e284e020441376c
Author: Andrew Kelley <superjoe30 at gmail.com>
Date: Sun Jun 29 21:52:58 2014 +0000
Imported Upstream version 0.2.0
---
.editorconfig | 16 ++++++++++++++++
.gitattributes | 1 +
.gitignore | 1 +
.jshintrc | 13 +++++++++++++
.travis.yml | 3 +++
cli.js | 28 ++++++++++++++++++++++++++++
index.js | 32 ++++++++++++++++++++++++++++++++
license | 21 +++++++++++++++++++++
package.json | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
readme.md | 44 ++++++++++++++++++++++++++++++++++++++++++++
test.js | 30 ++++++++++++++++++++++++++++++
11 files changed, 239 insertions(+)
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..8311fe1
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,16 @@
+# editorconfig.org
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[package.json]
+indent_style = space
+indent_size = 2
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..804f8af
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,13 @@
+{
+ "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
new file mode 100644
index 0000000..244b7e8
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - '0.10'
diff --git a/cli.js b/cli.js
new file mode 100755
index 0000000..0617971
--- /dev/null
+++ b/cli.js
@@ -0,0 +1,28 @@
+#!/usr/bin/env node
+'use strict';
+var pkg = require('./package.json');
+var supportsColor = require('./');
+var input = process.argv[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 (!input || process.argv.indexOf('--help') !== -1) {
+ help();
+ return;
+}
+
+if (process.argv.indexOf('--version') !== -1) {
+ console.log(pkg.version);
+ return;
+}
+
+process.exit(supportsColor ? 0 : 1);
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..092d0ba
--- /dev/null
+++ b/index.js
@@ -0,0 +1,32 @@
+'use strict';
+module.exports = (function () {
+ if (process.argv.indexOf('--no-color') !== -1) {
+ return false;
+ }
+
+ if (process.argv.indexOf('--color') !== -1) {
+ return true;
+ }
+
+ if (process.stdout && !process.stdout.isTTY) {
+ return false;
+ }
+
+ if (process.platform === 'win32') {
+ return true;
+ }
+
+ if ('COLORTERM' in process.env) {
+ return true;
+ }
+
+ if (process.env.TERM === 'dumb') {
+ return false;
+ }
+
+ if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) {
+ return true;
+ }
+
+ return false;
+})();
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..02b0197
--- /dev/null
+++ b/package.json
@@ -0,0 +1,50 @@
+{
+ "name": "supports-color",
+ "version": "0.2.0",
+ "description": "Detect whether a terminal supports color",
+ "license": "MIT",
+ "repository": "sindresorhus/supports-color",
+ "bin": {
+ "supports-color": "cli.js"
+ },
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus at gmail.com",
+ "url": "http://sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "mocha"
+ },
+ "files": [
+ "index.js",
+ "cli.js"
+ ],
+ "keywords": [
+ "cli",
+ "bin",
+ "color",
+ "colour",
+ "colors",
+ "terminal",
+ "console",
+ "cli",
+ "ansi",
+ "styles",
+ "tty",
+ "rgb",
+ "256",
+ "shell",
+ "xterm",
+ "command-line",
+ "support",
+ "supports",
+ "capability",
+ "detect"
+ ],
+ "devDependencies": {
+ "mocha": "*"
+ }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..7f07e5f
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,44 @@
+# supports-color [![Build Status](https://travis-ci.org/sindresorhus/supports-color.svg?branch=master)](https://travis-ci.org/sindresorhus/supports-color)
+
+> Detect whether a terminal supports color
+
+
+## Install
+
+```sh
+$ npm install --save supports-color
+```
+
+
+## Usage
+
+```js
+var supportsColor = require('supports-color');
+
+if (supportsColor) {
+ console.log('Terminal supports color');
+}
+```
+
+It obeys the `--color` and `--no-color` CLI flags.
+
+
+## CLI
+
+```sh
+$ npm install --global supports-color
+```
+
+```sh
+$ supports-color --help
+
+Usage
+ $ supports-color
+
+# Exits with code 0 if color is supported and 1 if not
+```
+
+
+## License
+
+MIT © [Sindre Sorhus](http://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..4c5c1e8
--- /dev/null
+++ b/test.js
@@ -0,0 +1,30 @@
+'use strict';
+var assert = require('assert');
+
+beforeEach(function () {
+ // clear the cache of the tested module
+ delete require.cache[require.resolve('./')];
+ process.stdout.isTTY = true;
+ process.argv = [];
+ process.env = {};
+});
+
+it('should return false if not TTY', function () {
+ process.stdout.isTTY = false;
+ assert.equal(require('./'), false);
+});
+
+it('should return false if --no-color flag is used', function () {
+ process.argv = ['--no-color'];
+ assert.equal(require('./'), false);
+});
+
+it('should return true if --color flag is used', function () {
+ process.argv = ['--color'];
+ assert.equal(require('./'), true);
+});
+
+it('should return true if `COLORTERM` is in env', function () {
+ process.env.COLORTERM = true;
+ assert.equal(require('./'), true);
+});
--
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