package/package.json000644 000765 000024 0000001460 13115611516013016 0ustar00000000 000000 { "name": "color-support", "version": "1.1.3", "description": "A module which will endeavor to guess your terminal's level of color support.", "main": "index.js", "browser": "browser.js", "bin": "bin.js", "devDependencies": { "tap": "^10.3.3" }, "scripts": { "test": "tap test/*.js --100 -J", "preversion": "npm test", "postversion": "npm publish", "postpublish": "git push origin --all; git push origin --tags" }, "repository": { "type": "git", "url": "git+https://github.com/isaacs/color-support.git" }, "keywords": [ "terminal", "color", "support", "xterm", "truecolor", "256" ], "author": "Isaac Z. Schlueter (http://blog.izs.me/)", "license": "ISC", "files": [ "browser.js", "index.js", "bin.js" ] } package/README.md000644 000765 000024 0000010746 12743066454012031 0ustar00000000 000000 # color-support A module which will endeavor to guess your terminal's level of color support. [![Build Status](https://travis-ci.org/isaacs/color-support.svg?branch=master)](https://travis-ci.org/isaacs/color-support) [![Coverage Status](https://coveralls.io/repos/github/isaacs/color-support/badge.svg?branch=master)](https://coveralls.io/github/isaacs/color-support?branch=master) This is similar to `supports-color`, but it does not read `process.argv`. 1. If not in a node environment, not supported. 2. If stdout is not a TTY, not supported, unless the `ignoreTTY` option is set. 3. If the `TERM` environ is `dumb`, not supported, unless the `ignoreDumb` option is set. 4. If on Windows, then support 16 colors. 5. If using Tmux, then support 256 colors. 7. Handle continuous-integration servers. If `CI` or `TEAMCITY_VERSION` are set in the environment, and `TRAVIS` is not set, then color is not supported, unless `ignoreCI` option is set. 6. Guess based on the `TERM_PROGRAM` environ. These terminals support 16m colors: - `iTerm.app` version 3.x supports 16m colors, below support 256 - `MacTerm` supports 16m colors - `Apple_Terminal` supports 256 colors - Have more things that belong on this list? Send a PR! 8. Make a guess based on the `TERM` environment variable. Any `xterm-256color` will get 256 colors. Any screen, xterm, vt100, color, ansi, cygwin, or linux `TERM` will get 16 colors. 9. If `COLORTERM` environment variable is set, then support 16 colors. 10. At this point, we assume that color is not supported. ## USAGE ```javascript var testColorSupport = require('color-support') var colorSupport = testColorSupport(/* options object */) if (!colorSupport) { console.log('color is not supported') } else if (colorSupport.has16m) { console.log('\x1b[38;2;102;194;255m16m colors\x1b[0m') } else if (colorSupport.has256) { console.log('\x1b[38;5;119m256 colors\x1b[0m') } else if (colorSupport.hasBasic) { console.log('\x1b[31mbasic colors\x1b[0m') } else { console.log('this is impossible, but colors are not supported') } ``` If you don't have any options to set, you can also just look at the flags which will all be set on the test function itself. (Of course, this doesn't return a falsey value when colors aren't supported, and doesn't allow you to set options.) ```javascript var colorSupport = require('color-support') if (colorSupport.has16m) { console.log('\x1b[38;2;102;194;255m16m colors\x1b[0m') } else if (colorSupport.has256) { console.log('\x1b[38;5;119m256 colors\x1b[0m') } else if (colorSupport.hasBasic) { console.log('\x1b[31mbasic colors\x1b[0m') } else { console.log('colors are not supported') } ``` ## Options You can pass in the following options. * ignoreTTY - default false. Ignore the `isTTY` check. * ignoreDumb - default false. Ignore `TERM=dumb` environ check. * ignoreCI - default false. Ignore `CI` environ check. * env - Object for environment vars. Defaults to `process.env`. * stream - Stream for `isTTY` check. Defaults to `process.stdout`. * term - String for `TERM` checking. Defaults to `env.TERM`. * alwaysReturn - default false. Return an object when colors aren't supported (instead of returning `false`). * level - A number from 0 to 3. This will return a result for the specified level. This is useful if you want to be able to set the color support level explicitly as a number in an environment variable or config, but then use the object flags in your program. Except for `alwaysReturn` to return an object for level 0, all other options are ignored, since no checking is done if a level is explicitly set. ## Return Value If no color support is available, then `false` is returned by default, unless the `alwaysReturn` flag is set to `true`. This is so that the simple question of "can I use colors or not" can treat any truthy return as "yes". Otherwise, the return object has the following fields: * `level` - A number from 0 to 3 * `0` - No color support * `1` - Basic (16) color support * `2` - 256 color support * `3` - 16 million (true) color support * `hasBasic` - Boolean * `has256` - Boolean * `has16m` - Boolean ## CLI You can run the `color-support` bin from the command line which will just dump the values as this module calculates them in whatever env it's run. It takes no command line arguments. ## Credits This is a spiritual, if not actual, fork of [supports-color](http://npm.im/supports-color) by the ever prolific [Sindre Sorhus](http://npm.im/~sindresorhus). package/LICENSE000644 000765 000024 0000001375 12742632471011552 0ustar00000000 000000 The ISC License Copyright (c) Isaac Z. Schlueter and Contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. package/bin.js000755 000765 000024 0000000177 12742631236011653 0ustar00000000 000000 #!/usr/bin/env node var colorSupport = require('./')({alwaysReturn: true }) console.log(JSON.stringify(colorSupport, null, 2)) package/browser.js000644 000765 000024 0000000453 12742633140012554 0ustar00000000 000000 module.exports = colorSupport({ alwaysReturn: true }, colorSupport) function colorSupport(options, obj) { obj = obj || {} options = options || {} obj.level = 0 obj.hasBasic = false obj.has256 = false obj.has16m = false if (!options.alwaysReturn) { return false } return obj } package/index.js000644 000765 000024 0000005124 13115611374012200 0ustar00000000 000000 // call it on itself so we can test the export val for basic stuff module.exports = colorSupport({ alwaysReturn: true }, colorSupport) function hasNone (obj, options) { obj.level = 0 obj.hasBasic = false obj.has256 = false obj.has16m = false if (!options.alwaysReturn) { return false } return obj } function hasBasic (obj) { obj.hasBasic = true obj.has256 = false obj.has16m = false obj.level = 1 return obj } function has256 (obj) { obj.hasBasic = true obj.has256 = true obj.has16m = false obj.level = 2 return obj } function has16m (obj) { obj.hasBasic = true obj.has256 = true obj.has16m = true obj.level = 3 return obj } function colorSupport (options, obj) { options = options || {} obj = obj || {} // if just requesting a specific level, then return that. if (typeof options.level === 'number') { switch (options.level) { case 0: return hasNone(obj, options) case 1: return hasBasic(obj) case 2: return has256(obj) case 3: return has16m(obj) } } obj.level = 0 obj.hasBasic = false obj.has256 = false obj.has16m = false if (typeof process === 'undefined' || !process || !process.stdout || !process.env || !process.platform) { return hasNone(obj, options) } var env = options.env || process.env var stream = options.stream || process.stdout var term = options.term || env.TERM || '' var platform = options.platform || process.platform if (!options.ignoreTTY && !stream.isTTY) { return hasNone(obj, options) } if (!options.ignoreDumb && term === 'dumb' && !env.COLORTERM) { return hasNone(obj, options) } if (platform === 'win32') { return hasBasic(obj) } if (env.TMUX) { return has256(obj) } if (!options.ignoreCI && (env.CI || env.TEAMCITY_VERSION)) { if (env.TRAVIS) { return has256(obj) } else { return hasNone(obj, options) } } // TODO: add more term programs switch (env.TERM_PROGRAM) { case 'iTerm.app': var ver = env.TERM_PROGRAM_VERSION || '0.' if (/^[0-2]\./.test(ver)) { return has256(obj) } else { return has16m(obj) } case 'HyperTerm': case 'Hyper': return has16m(obj) case 'MacTerm': return has16m(obj) case 'Apple_Terminal': return has256(obj) } if (/^xterm-256/.test(term)) { return has256(obj) } if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(term)) { return hasBasic(obj) } if (env.COLORTERM) { return hasBasic(obj) } return hasNone(obj, options) }