cli-progress-box
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "cli-progress-box", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Quick visual change detection indicator", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -76,4 +76,4 @@ ![](https://i.imgur.com/xFMQ3Y3.gif) | ||
if ( !opts.clcColor ) opts.clcColor = 'bgMagentaBright' | ||
if ( !opts.character ) opts.character = ' ' | ||
if ( !opts.colors ) opts.colors = clcBgColors.bright.slice() // color changes based on opts.step | ||
@@ -80,0 +80,0 @@ if ( !opts.getHeader ) opts.getHeader = function ( opts ) { return '' } |
202
src/index.js
@@ -20,3 +20,3 @@ /* | ||
if ( !opts.step ) opts.step = 0 | ||
if ( !opts.step ) opts.step = 0 // will mutate | ||
if ( !opts.maxStep ) opts.maxStep = 4 | ||
@@ -31,4 +31,4 @@ | ||
if ( !opts.clcColor ) opts.clcColor = 'bgMagentaBright' | ||
if ( !opts.character ) opts.character = ' ' | ||
if ( !opts.colors ) opts.colors = clcBgColors.bright.slice() | ||
@@ -38,2 +38,4 @@ if ( !opts.getHeader ) opts.getHeader = function ( opts ) { return '' } | ||
if ( !opts.ontick ) opts.ontick = function ( opts ) { return opts } | ||
if ( !opts.transform ) opts.transform = _transform | ||
@@ -46,2 +48,4 @@ if ( !opts.render ) opts.render = _render | ||
var api = function progressBox ( step ) { | ||
opts = opts.ontick && opts.ontick( opts ) || opts | ||
opts.content = opts.transform( opts, step ) | ||
@@ -59,86 +63,6 @@ return opts.content | ||
// helpers for background colors | ||
api.bgColors = { | ||
dark: [ | ||
'bgBlack', | ||
'bgRed', | ||
'bgGreen', | ||
'bgYellow', | ||
'bgBlue', | ||
'bgMagenta', | ||
'bgCyan', | ||
'bgWhite' | ||
], | ||
bright: [ | ||
'bgBlackBright', | ||
'bgRedBright', | ||
'bgGreenBright', | ||
'bgYellowBright', | ||
'bgBlueBright', | ||
'bgMagentaBright', | ||
'bgCyanBright', | ||
'bgWhiteBright' | ||
], | ||
all: [ | ||
'bgBlack', | ||
'bgRed', | ||
'bgGreen', | ||
'bgYellow', | ||
'bgBlue', | ||
'bgMagenta', | ||
'bgCyan', | ||
'bgWhite', | ||
'bgBlackBright', | ||
'bgRedBright', | ||
'bgGreenBright', | ||
'bgYellowBright', | ||
'bgBlueBright', | ||
'bgMagentaBright', | ||
'bgCyanBright', | ||
'bgWhiteBright' | ||
] | ||
} | ||
// helpers | ||
api.bgColors = clcBgColors | ||
api.fgColors = clcFgColors | ||
// helpers for foreground colors | ||
api.fgColors = { | ||
dark: [ | ||
'black', | ||
'red', | ||
'green', | ||
'yellow', | ||
'blue', | ||
'magenta', | ||
'cyan', | ||
'white' | ||
], | ||
bright: [ | ||
'blackBright', | ||
'redBright', | ||
'greenBright', | ||
'yellowBright', | ||
'blueBright', | ||
'magentaBright', | ||
'cyanBright', | ||
'whiteBright' | ||
], | ||
all: [ | ||
'black', | ||
'red', | ||
'green', | ||
'yellow', | ||
'blue', | ||
'magenta', | ||
'cyan', | ||
'white', | ||
'blackBright', | ||
'redBright', | ||
'greenBright', | ||
'yellowBright', | ||
'blueBright', | ||
'magentaBright', | ||
'cyanBright', | ||
'whiteBright' | ||
] | ||
} | ||
return api | ||
@@ -179,4 +103,23 @@ } | ||
{ | ||
var colors = opts.colors | ||
if ( typeof opts.colors === 'function' ) { | ||
colors = opts.colors( opts ) | ||
} | ||
if ( typeof colors === 'string' ) { | ||
colors = colors.split( /\s+/ ) | ||
} | ||
if ( typeof colors === 'object' ) { | ||
colors = colors | ||
} | ||
var color = colors[ opts.step % colors.length ] | ||
if ( opts.color ) color = opts.color | ||
if ( opts.clcColor ) color = opts.clcColor | ||
var box = opts.generateBox( opts ) | ||
return clc[ opts.clcColor ]( box ) | ||
return clc[ color ]( box ) | ||
} | ||
@@ -196,1 +139,88 @@ | ||
} | ||
// helpers for background colors | ||
var clcBgColors = { | ||
dark: [ | ||
'bgBlack', | ||
'bgRed', | ||
'bgGreen', | ||
'bgYellow', | ||
'bgBlue', | ||
'bgMagenta', | ||
'bgCyan', | ||
'bgWhite' | ||
], | ||
bright: [ | ||
'bgBlackBright', | ||
'bgRedBright', | ||
'bgGreenBright', | ||
'bgYellowBright', | ||
'bgBlueBright', | ||
'bgMagentaBright', | ||
'bgCyanBright', | ||
'bgWhiteBright' | ||
], | ||
all: [ | ||
'bgBlack', | ||
'bgRed', | ||
'bgGreen', | ||
'bgYellow', | ||
'bgBlue', | ||
'bgMagenta', | ||
'bgCyan', | ||
'bgWhite', | ||
'bgBlackBright', | ||
'bgRedBright', | ||
'bgGreenBright', | ||
'bgYellowBright', | ||
'bgBlueBright', | ||
'bgMagentaBright', | ||
'bgCyanBright', | ||
'bgWhiteBright' | ||
] | ||
} | ||
// helpers for foreground colors | ||
var clcFgColors = { | ||
dark: [ | ||
'black', | ||
'red', | ||
'green', | ||
'yellow', | ||
'blue', | ||
'magenta', | ||
'cyan', | ||
'white' | ||
], | ||
bright: [ | ||
'blackBright', | ||
'redBright', | ||
'greenBright', | ||
'yellowBright', | ||
'blueBright', | ||
'magentaBright', | ||
'cyanBright', | ||
'whiteBright' | ||
], | ||
all: [ | ||
'black', | ||
'red', | ||
'green', | ||
'yellow', | ||
'blue', | ||
'magenta', | ||
'cyan', | ||
'white', | ||
'blackBright', | ||
'redBright', | ||
'greenBright', | ||
'yellowBright', | ||
'blueBright', | ||
'magentaBright', | ||
'cyanBright', | ||
'whiteBright' | ||
] | ||
} | ||
module.exports.bgColors = clcBgColors | ||
module.exports.fgColors = clcFgColors |
7787
183