How to use the supports-color.stdout function in supports-color

To help you get started, we’ve selected a few supports-color 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 vweevers / hallmark / options.js View on Github external
'use strict'

const color = require('supports-color').stdout
const extensions = require('markdown-extensions')
const processor = require('remark')

module.exports = function (argv, pkg, packageOpts, files, cwd, repository) {
  let reporter
  let reporterOptions

  if (argv.report) {
    // Only take one --report option
    reporter = [].concat(argv.report)[0]

    if (typeof reporter !== 'string') {
      // Reporter was specified with subarg syntax
      reporterOptions = reporter
      reporter = reporter._[0]
    }
github remy / nodemon / lib / help / index.js View on Github external
var fs = require('fs');
var path = require('path');
const supportsColor = require('supports-color');

module.exports = help;

const highlight = supportsColor.stdout ? '\x1B\[$1m' : '';

function help(item) {
  if (!item) {
    item = 'help';
  } else if (item === true) { // if used with -h or --help and no args
    item = 'help';
  }

  // cleanse the filename to only contain letters
  // aka: /\W/g but figured this was eaiser to read
  item = item.replace(/[^a-z]/gi, '');

  try {
    var dir = path.join(__dirname, '..', '..', 'doc', 'cli', item + '.txt');
    var body = fs.readFileSync(dir, 'utf8');
    return body.replace(/\\x1B\[(.)m/g, highlight);
github satoripop / thesuperlogger / src / transports / winston-console.js View on Github external
const util = require('util');
const chalk = require('chalk');
const supportsColor = require('supports-color');
const moment = require('moment');
const { LEVEL } = require('triple-beam');
const TransportStream = require('winston-transport');
const helpers = require('./helpers');
const {colors} = require('../helpers/levelsSettings');
const _ = require('lodash');

let ansi = new chalk.constructor({level: 0});
if (supportsColor.stderr.has16m) {
	ansi = new chalk.constructor({level: 3});
} else if (supportsColor.stdout.has256) {
	ansi = new chalk.constructor({level: 2});
} else if (supportsColor.stdout) {
	ansi = new chalk.constructor({level: 1});
}

//
// ### function Console (options)
// #### @options {Object} Options for this instance.
// Constructor function for the Console transport object responsible
// for persisting log messages and metadata to a terminal or TTY.
//
var Console = module.exports = function (options) {
	options = options || {};
	TransportStream.call(this, options);
	this.stderrLevels = getStderrLevels(options.stderrLevels, options.debugStdout);
	this.eol = os.EOL;

	//
github istanbuljs / istanbuljs / packages / istanbul-lib-report / lib / file-writer.js View on Github external
colorize(str, clazz) {
        const colors = {
            low: '31;1',
            medium: '33;1',
            high: '32;1'
        };

        /* istanbul ignore next: different modes for CI and local */
        if (supportsColor.stdout && colors[clazz]) {
            return `\u001b[${colors[clazz]}m${str}\u001b[0m`;
        }
        return str;
    }
}
github cypress-io / cypress / cli / lib / util.js View on Github external
supportsColor () {
    // if we've been explictly told not to support
    // color then turn this off
    if (process.env.NO_COLOR) {
      return false
    }

    // https://github.com/cypress-io/cypress/issues/1747
    // always return true in CI providers
    if (process.env.CI) {
      return true
    }

    // ensure that both stdout and stderr support color
    return Boolean(supportsColor.stdout) && Boolean(supportsColor.stderr)
  },
github sindresorhus / grunt-concurrent / gruntfile.js View on Github external
grunt.registerTask('colorcheck', () => {
		// Writes 'true' or 'false' to the file
		const supports = String(Boolean(supportsColor.stdout));
		grunt.file.write('test/tmp/colors', supports);
	});
github tecfu / tty-table / dist / tty-table.js View on Github external
(function (process){
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const ansiStyles = require('ansi-styles');
const stdoutColor = require('supports-color').stdout;

const template = require('./templates.js');

const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');

// `supportsColor.level` → `ansiStyles.color[name]` mapping
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];

// `color-convert` models to exclude from the Chalk API due to conflicts and such
const skipModels = new Set(['gray']);

const styles = Object.create(null);

function applyOptions(obj, options) {
	options = options || {};
github ehmicky / log-process-errors / test / colors.js View on Github external
test.serial(`should colorize the error | ${title}`, async t => {
    const { stopLogging, log } = startLogging({ log: 'spy', eventName })

    await emit()

    t.true(log.calledOnce)
    t.false(hasAnsi(String(log.firstCall.args[0])))
    t.false(hasAnsi(log.firstCall.args[0].stack))
    t.is(hasAnsi(inspect(log.firstCall.args[0])), Boolean(supportsColor.stdout))

    stopLogging()
  })
github binaris / binaris / lib / logger.js View on Github external
const formatter = function formatter(options) {
  const body = options.message ? options.message : '';
  const suffix = (options.meta && Object.keys(options.meta).length
    ? `\n\t${JSON.stringify(options.meta)}` : '');

  const fullLog = `${body}${suffix}`;
  return supportsColor.stdout ? config.colorize(options.level, fullLog) : fullLog;
};
github elastic / kibana / packages / kbn-interpreter / tasks / build / cli.js View on Github external
withProcRunner(log, async (proc) => {
  log.info('Deleting old output');
  await del(BUILD_DIR);

  const cwd = ROOT_DIR;
  const env = { ...process.env };
  if (supportsColor.stdout) {
    env.FORCE_COLOR = 'true';
  }

  log.info(`Starting babel ${flags.watch ? ' in watch mode' : ''}`);
  await Promise.all([
    proc.run('babel  ', {
      cmd: 'babel',
      args: [
        'src',
        '--ignore', `*.test.js`,
        '--out-dir', relative(cwd, BUILD_DIR),
        '--copy-files',
        ...(flags.dev ? ['--source-maps', 'inline'] : []),
        ...(flags.watch ? ['--watch'] : ['--quiet'])
      ],
      wait: true,