"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/chalk/index.js" (7 Feb 2017, 3154 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict';
    2 var escapeStringRegexp = require('escape-string-regexp');
    3 var ansiStyles = require('ansi-styles');
    4 var stripAnsi = require('strip-ansi');
    5 var hasAnsi = require('has-ansi');
    6 var supportsColor = require('supports-color');
    7 var defineProps = Object.defineProperties;
    8 var isSimpleWindowsTerm = process.platform === 'win32' && !/^xterm/i.test(process.env.TERM);
    9 
   10 function Chalk(options) {
   11     // detect mode if not set manually
   12     this.enabled = !options || options.enabled === undefined ? supportsColor : options.enabled;
   13 }
   14 
   15 // use bright blue on Windows as the normal blue color is illegible
   16 if (isSimpleWindowsTerm) {
   17     ansiStyles.blue.open = '\u001b[94m';
   18 }
   19 
   20 var styles = (function () {
   21     var ret = {};
   22 
   23     Object.keys(ansiStyles).forEach(function (key) {
   24         ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
   25 
   26         ret[key] = {
   27             get: function () {
   28                 return build.call(this, this._styles.concat(key));
   29             }
   30         };
   31     });
   32 
   33     return ret;
   34 })();
   35 
   36 var proto = defineProps(function chalk() {}, styles);
   37 
   38 function build(_styles) {
   39     var builder = function () {
   40         return applyStyle.apply(builder, arguments);
   41     };
   42 
   43     builder._styles = _styles;
   44     builder.enabled = this.enabled;
   45     // __proto__ is used because we must return a function, but there is
   46     // no way to create a function with a different prototype.
   47     /* eslint-disable no-proto */
   48     builder.__proto__ = proto;
   49 
   50     return builder;
   51 }
   52 
   53 function applyStyle() {
   54     // support varags, but simply cast to string in case there's only one arg
   55     var args = arguments;
   56     var argsLen = args.length;
   57     var str = argsLen !== 0 && String(arguments[0]);
   58 
   59     if (argsLen > 1) {
   60         // don't slice `arguments`, it prevents v8 optimizations
   61         for (var a = 1; a < argsLen; a++) {
   62             str += ' ' + args[a];
   63         }
   64     }
   65 
   66     if (!this.enabled || !str) {
   67         return str;
   68     }
   69 
   70     var nestedStyles = this._styles;
   71     var i = nestedStyles.length;
   72 
   73     // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
   74     // see https://github.com/chalk/chalk/issues/58
   75     // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
   76     var originalDim = ansiStyles.dim.open;
   77     if (isSimpleWindowsTerm && (nestedStyles.indexOf('gray') !== -1 || nestedStyles.indexOf('grey') !== -1)) {
   78         ansiStyles.dim.open = '';
   79     }
   80 
   81     while (i--) {
   82         var code = ansiStyles[nestedStyles[i]];
   83 
   84         // Replace any instances already present with a re-opening code
   85         // otherwise only the part of the string until said closing code
   86         // will be colored, and the rest will simply be 'plain'.
   87         str = code.open + str.replace(code.closeRe, code.open) + code.close;
   88     }
   89 
   90     // Reset the original 'dim' if we changed it to work around the Windows dimmed gray issue.
   91     ansiStyles.dim.open = originalDim;
   92 
   93     return str;
   94 }
   95 
   96 function init() {
   97     var ret = {};
   98 
   99     Object.keys(styles).forEach(function (name) {
  100         ret[name] = {
  101             get: function () {
  102                 return build.call(this, [name]);
  103             }
  104         };
  105     });
  106 
  107     return ret;
  108 }
  109 
  110 defineProps(Chalk.prototype, init());
  111 
  112 module.exports = new Chalk();
  113 module.exports.styles = ansiStyles;
  114 module.exports.hasColor = hasAnsi;
  115 module.exports.stripColor = stripAnsi;
  116 module.exports.supportsColor = supportsColor;