Skip to content

Commit

Permalink
Remove supports-color
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 21, 2021
1 parent 5bf2a1e commit db4d4d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -38,7 +38,6 @@
"is-plain-obj": "^3.0.0",
"jest-validate": "^26.6.2",
"read-pkg-up": "^7.0.1",
"supports-color": "^8.1.0",
"update-notifier": "^5.0.1",
"yargs": "^16.2.0"
},
Expand Down
31 changes: 26 additions & 5 deletions src/print/colors.js
@@ -1,17 +1,38 @@
import { stdout } from 'process'

import Chalk from 'chalk'
import { stdout as supportsColor } from 'supports-color'

// Retrieve `chalk` instance.
// Allows forcing `colors` with `true` or `false` (default: guessed).
// Use `stdout.getColorDepth()` instead of chalk's default behavior (relying
// on `supports-color`) because it behaves more correctly.
export const getChalk = function (colors) {
const level = getLevel(colors)
return new Chalk.Instance({ level })
const chalk = new Chalk.Instance({ level })
return chalk
}

const getLevel = function (colors) {
if (!colors) {
if (colors === false) {
return 0
}

const terminalLevel = getTerminalLevel()

if (colors === undefined) {
return terminalLevel
}

return Math.max(terminalLevel, 1)
}

const getTerminalLevel = function () {
if (!stdout.isTTY) {
return 0
}

return Math.max(supportsColor.level, 1)
return DEPTH_TO_LEVEL[stdout.getColorDepth()]
}

export const DEFAULT_COLORS = Boolean(supportsColor)
// Maps chalk levels to color depth
const DEPTH_TO_LEVEL = { 1: 0, 4: 1, 8: 2, 24: 3 }
3 changes: 0 additions & 3 deletions src/print/options.js
Expand Up @@ -4,8 +4,6 @@ import {
EXAMPLE_OPTS as exampleParseOpts,
} from '../parse/options.js'

import { DEFAULT_COLORS } from './colors.js'

// Normalize options and assign default values
// Do not handle options already handled by abstract-parser
export const getOpts = function (opts = {}) {
Expand All @@ -17,7 +15,6 @@ export const getOpts = function (opts = {}) {

export const DEFAULT_OPTS = {
...defaultParseOpts,
colors: DEFAULT_COLORS,
}

export const EXAMPLE_OPTS = {
Expand Down

0 comments on commit db4d4d6

Please sign in to comment.