Skip to content

Instantly share code, notes, and snippets.

@bobisme
Created May 30, 2017 22:36
Show Gist options
  • Save bobisme/2c3bb4e9dd66cf16994b55f313e4b505 to your computer and use it in GitHub Desktop.
Save bobisme/2c3bb4e9dd66cf16994b55f313e4b505 to your computer and use it in GitHub Desktop.
const color = (() => {
const RESET = '\x1b[0m'
const BRIGHT = '\x1b[1m'
const DIM = '\x1b[2m'
const RED = '\x1b[31m'
const GREEN = '\x1b[32m'
const YELLOW = '\x1b[33m'
const BLUE = '\x1b[34m'
const MAGENTA = '\x1b[35m'
const CYAN = '\x1b[36m'
let colorCode = (code, msg) => `${code}${msg}${RESET}`
let colorFn = code => (msg => colorCode(code, msg))
let colors = {
bright: colorFn(BRIGHT),
dim: colorFn(DIM),
red: colorFn(RED),
green: colorFn(GREEN),
yellow: colorFn(YELLOW),
blue: colorFn(BLUE),
magenta: colorFn(MAGENTA),
cyan: colorFn(CYAN),
}
let brighten = colorFn => (msg => `${BRIGHT}${colorFn(msg)}`)
let dimmer = colorFn => (msg => `${DIM}${colorFn(msg)}`)
let colorKeys = Object.keys(colors)
colors.bright = {}
colors.dim = {}
colorKeys.forEach(color => {
colors.bright[color] = brighten(colors[color])
colors.dim[color] = dimmer(colors[color])
})
return colors
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment