@buzuli/color
Advanced tools
Comparing version 2.3.1 to 2.3.2
@@ -6,11 +6,36 @@ const chalk = require('chalk') | ||
const defaultColorLevel = 3 | ||
const context = { chalk } | ||
const context = { chalk, level: defaultColorLevel } | ||
function setColorLevel (desiredLevel) { | ||
const colorLevel = Number(desiredLevel) | ||
const level = isNaN(colorLevel) ? defaultColorLevel : (colorLevel <= 0) ? 0 : (colorLevel > 3) ? 3 : colorLevel | ||
let level = colorLevel | ||
if (isNaN(colorLevel)) { | ||
level = defaultColorLevel | ||
} else if (colorLevel < 0) { | ||
level = 0 | ||
} else if (colorLevel > 3) { | ||
level = 3 | ||
} | ||
context.level = level | ||
context.chalk = new chalk.Instance({ level }) | ||
return level | ||
} | ||
setColorLevel(process.env.BUZULI_COLOR_LEVEL) | ||
function getColorLevel () { | ||
return context.level | ||
} | ||
function initColor (ignoreTTY=false) { | ||
const desiredColorLevel = process.env.BUZULI_COLOR_LEVEL | ||
const forceColorOff = !process.stdout.isTTY && !ignoreTTY | ||
const resolvedColorLevel = forceColorOff ? 0 : desiredColorLevel | ||
setColorLevel(resolvedColorLevel) | ||
} | ||
initColor() | ||
const light = process.env.BUZULI_COLOR_LIGHT | ||
@@ -53,3 +78,5 @@ const dark = process.env.BUZULI_COLOR_DARK | ||
pool: colorPool, | ||
setColorLevel | ||
initColor, | ||
setColorLevel, | ||
getColorLevel, | ||
} | ||
@@ -56,0 +83,0 @@ |
{ | ||
"name": "@buzuli/color", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "Preferred colors for @buzuli's projects", | ||
@@ -5,0 +5,0 @@ "main": "lib/color.js", |
11588
8
278
23