mirror of
https://github.com/flynx/colors.js.git
synced 2025-10-29 11:00:11 +00:00
Update supports-colors.js
This commit is contained in:
parent
9f3ace4470
commit
c74f2c3088
@ -1,61 +1,73 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
'use strict';
|
||||
var hasFlag = require('has-flag');
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
var support = function (level) {
|
||||
if (level === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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:
|
||||
return {
|
||||
level: level,
|
||||
hasBasic: true,
|
||||
has256: level >= 2,
|
||||
has16m: level >= 3
|
||||
};
|
||||
};
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
var supportLevel = (function () {
|
||||
if (hasFlag('no-color') ||
|
||||
hasFlag('no-colors') ||
|
||||
hasFlag('color=false')) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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.
|
||||
if (hasFlag('color=16m') ||
|
||||
hasFlag('color=full') ||
|
||||
hasFlag('color=truecolor')) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
*/
|
||||
if (hasFlag('color=256')) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
var argv = process.argv;
|
||||
if (hasFlag('color') ||
|
||||
hasFlag('colors') ||
|
||||
hasFlag('color=true') ||
|
||||
hasFlag('color=always')) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
module.exports = (function () {
|
||||
if (argv.indexOf('--no-color') !== -1 ||
|
||||
argv.indexOf('--color=false') !== -1) {
|
||||
return false;
|
||||
}
|
||||
if (process.stdout && !process.stdout.isTTY) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argv.indexOf('--color') !== -1 ||
|
||||
argv.indexOf('--color=true') !== -1 ||
|
||||
argv.indexOf('--color=always') !== -1) {
|
||||
return true;
|
||||
}
|
||||
if (process.platform === 'win32') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (process.stdout && !process.stdout.isTTY) {
|
||||
return false;
|
||||
}
|
||||
if ('COLORTERM' in process.env) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === 'dumb') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ('COLORTERM' in process.env) {
|
||||
return true;
|
||||
}
|
||||
if (/^xterm-256(?:color)?/.test(process.env.TERM)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (process.env.TERM === 'dumb') {
|
||||
return false;
|
||||
}
|
||||
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) {
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
})();
|
||||
|
||||
if (supportLevel === 0 && 'FORCE_COLOR' in process.env) {
|
||||
supportLevel = 1;
|
||||
}
|
||||
|
||||
module.exports = process && support(supportLevel);
|
||||
|
||||
return false;
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user