Skip to content

Commit

Permalink
Fix colors-option v3
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Nov 21, 2021
1 parent 2b085c3 commit e2912bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"abort-controller": "^3.0.0",
"bytes": "^3.1.1",
"cli-cursor": "^4.0.0",
"color-convert": "^2.0.1",
"colors-option": "^3.0.0",
"decamelize": "^6.0.0",
"delay": "^5.0.0",
Expand Down
12 changes: 9 additions & 3 deletions src/report/utils/colors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import colorConvert from 'color-convert'
import colorsOption from 'colors-option'

const chalk = colorsOption()
const { redBright, level } = chalk

const hslToChalk = function (hue, saturation, lightness) {
const [red, green, blue] = colorConvert.hsl.rgb([hue, saturation, lightness])
return chalk.rgb(red, green, blue)
}

// Main color
const MAIN_HUE = 175
const MAIN_SATURATION = 75
const MAIN_LIGHTNESS = 55
const mainColor = chalk.hsl(MAIN_HUE, MAIN_SATURATION, MAIN_LIGHTNESS)
const mainColor = hslToChalk(MAIN_HUE, MAIN_SATURATION, MAIN_LIGHTNESS)

// Gray shade.
// Bright enough to be accessible
const GRAY_LIGHTNESS = 55
const grayColor = chalk.hsl(0, 0, GRAY_LIGHTNESS)
const grayColor = hslToChalk(0, 0, GRAY_LIGHTNESS)

export const titleColor = mainColor.bold
export const subtitleColor = mainColor
Expand All @@ -28,7 +34,7 @@ export const suffixColor = grayColor
export const graphGradientColor = function (percentage) {
const percentageA = level < 3 ? 0 : percentage
const lightness = MAX_GRAPH_LIGHTNESS - percentageA * MAX_GRAPH_SHADE
return chalk.hsl(MAIN_HUE, MAIN_SATURATION, lightness)
return hslToChalk(MAIN_HUE, MAIN_SATURATION, lightness)
}

// Choosen to work well in 4, 8 and 24-bit colors
Expand Down

0 comments on commit e2912bd

Please sign in to comment.