How to use the ansi-styles.color function in ansi-styles

To help you get started, we’ve selected a few ansi-styles examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hitext / hitext / src / printer / tty.js View on Github external
return style.reduce((result, name) => {
        switch (true) {
            case name in styles.color:
                result.color = styles.color[name].open;
                break;

            case name in styles.bgColor:
                result.bgColor = styles.bgColor[name].open;
                break;

            case name === 'reset':
                result.color = '\u001B[39m';
                result.bgColor = '\u001B[49m';
                break;

            // default:
            //     console.error('Unknown modifier:', name);
        }
github skygragon / leetcode-cli / lib / chalk.js View on Github external
chalk.sprint = function(s, hex) {
  const color = chalk.use16m ? style.color.ansi16m.hex(hex)
                             : chalk.use256 ? style.color.ansi256.hex(hex)
                                            : style.color.ansi.hex(hex);
  return color + s + style.color.close;
};
github tecfu / tty-table / dist / tty-table.js View on Github external
styles[key] = {
		get() {
			const codes = ansiStyles[key];
			return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
		}
	};
}

styles.visible = {
	get() {
		return build.call(this, this._styles || [], true, 'visible');
	}
};

ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
for (const model of Object.keys(ansiStyles.color.ansi)) {
	if (skipModels.has(model)) {
		continue;
	}

	styles[model] = {
		get() {
			const level = this.level;
			return function () {
				const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
				const codes = {
					open,
					close: ansiStyles.color.close,
					closeRe: ansiStyles.color.closeRe
				};
				return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
github ENaranjo95 / 21Savage / .gitignore / node_modules / chalk / index.js View on Github external
styles[key] = {
		get() {
			const codes = ansiStyles[key];
			return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
		}
	};
}

styles.visible = {
	get() {
		return build.call(this, this._styles || [], true, 'visible');
	}
};

ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
for (const model of Object.keys(ansiStyles.color.ansi)) {
	if (skipModels.has(model)) {
		continue;
	}

	styles[model] = {
		get() {
			const level = this.level;
			return function () {
				const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
				const codes = {
					open,
					close: ansiStyles.color.close,
					closeRe: ansiStyles.color.closeRe
				};
				return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
github GoogleContainerTools / kpt / docsy / node_modules / autoprefixer / node_modules / chalk / index.js View on Github external
styles[key] = {
		get() {
			const codes = ansiStyles[key];
			return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
		}
	};
}

styles.visible = {
	get() {
		return build.call(this, this._styles || [], true, 'visible');
	}
};

ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
for (const model of Object.keys(ansiStyles.color.ansi)) {
	if (skipModels.has(model)) {
		continue;
	}

	styles[model] = {
		get() {
			const level = this.level;
			return function () {
				const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
				const codes = {
					open,
					close: ansiStyles.color.close,
					closeRe: ansiStyles.color.closeRe
				};
				return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
github sapegin / q-i / index.js View on Github external
const color = (v, c) => `${ansi.color[c].open}${v}${ansi.color.close}`;
github tecfu / tty-table / dist / tty-table.js View on Github external
return function () {
				const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
				const codes = {
					open,
					close: ansiStyles.color.close,
					closeRe: ansiStyles.color.closeRe
				};
				return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
			};
		}
github GoogleContainerTools / kpt / docsy / node_modules / autoprefixer / node_modules / chalk / index.js View on Github external
return function () {
				const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
				const codes = {
					open,
					close: ansiStyles.color.close,
					closeRe: ansiStyles.color.closeRe
				};
				return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
			};
		}
github skygragon / leetcode-cli / lib / chalk.js View on Github external
for (let f of file.listCodeDir('colors')) {
    const theme = {};
    const data = _.extendOwn({}, DEFAULT, f.data);
    for (let x of _.pairs(data)) {
      const k = x[0];
      const v = x[1];
      const bgK = bgName(k);

      if (chalk.use16m) {
        theme[k] = style.color.ansi16m.hex(v);
        theme[bgK] = style.bgColor.ansi16m.hex(v);
      } else if (chalk.use256) {
        theme[k] = style.color.ansi256.hex(v);
        theme[bgK] = style.bgColor.ansi256.hex(v);
      } else {
        theme[k] = style.color.ansi.hex(v);
        theme[bgK] = style.bgColor.ansi.hex(v);
      }
    }
    chalk.themes.set(f.name, theme);
  }

  for (let color of ['black', 'blue', 'cyan', 'gray', 'green', 'magenta', 'red', 'white', 'yellow']) {
    Object.defineProperty(chalk, color, {
      get:          () => chalk.wrap(chalk.theme[color], style.color.close),
      configurable: true
    });
    const bgcolor = bgName(color);
    Object.defineProperty(chalk, bgcolor, {
      get:          () => chalk.wrap(chalk.theme[bgcolor], style.bgColor.close),
      configurable: true
    });