Skip to content

Commit

Permalink
fix: only one color ending parameter is enough
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Oct 10, 2018
1 parent 2afb025 commit d213634
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 68 deletions.
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,16 @@ The following variables are supported:

##### `FancyReporter`
- `%1$s`: Start text color
- `%2$s`: End text color
- `%3$s`: Start additional text color
- `%4$s`: End additional text color
- `%5$s`: Start background color
- `%6$s`: End background color
- `%7$s`: Date string as formatted by `timeFormat`
- `%8$s`: Log type, e.g. SUCCESS
- `%9$s`: Tag
- `%10$s`: Log message
- `%11$s`: Additional fields
- `%12$s`: Figure icon
- `%13$s`: Length of figure icon string + 1 if icon exists, used for conditional space after icon
- `%2$s`: Start additional text color
- `%3$s`: Start background color
- `%4$s`: End all (background) colors
- `%5$s`: Date string as formatted by `timeFormat`
- `%6$s`: Log type, e.g. SUCCESS
- `%7$s`: Tag
- `%8$s`: Log message
- `%9$s`: Additional fields
- `%10$s`: Figure icon
- `%11$s`: Length of figure icon string + 1 if icon exists, used for conditional space after icon

```js
consola = new Consola({
Expand All @@ -189,15 +187,15 @@ consola = new Consola({
}),
new FancyReporter({
formats: {
default: '[%7$s] [%8$-7s] %9$s%10$s%11$s\n', // same format as BasicReporter
default: '[%5$s] [%6$-7s] %7$s%8$s%9$s\n', // same format as BasicReporter
badge: '\n' +
' /================================================\\\n' +
' |%5$s' + '%12$s'.repeat(48) + '%6$s|\n' +
' |%5$s%12$s' + ' '.repeat(46) + '%12$s%6$s|\n' +
' |%5$s%12$s %8$-44s %12$s%6$s|\n' +
' |%5$s%12$s %10$-44s %12$s%6$s|\n' +
' |%5$s%12$s' + ' '.repeat(46) + '%12$s%6$s|\n' +
' |%5$s' + '%12$s'.repeat(48) + '%6$s|\n' +
' |%3$s' + '%10$s'.repeat(48) + '%4$s|\n' +
' |%3$s%10$s' + ' '.repeat(46) + '%10$s%4$s|\n' +
' |%3$s%10$s %6$-44s %10$s%4$s|\n' +
' |%3$s%10$s %8$-44s %10$s%4$s|\n' +
' |%3$s%10$s' + ' '.repeat(46) + '%10$s%4$s|\n' +
' |%3$s' + '%10$s'.repeat(48) + '%4$s|\n' +
' \\================================================/\n\n'
}
})
Expand Down
62 changes: 30 additions & 32 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,37 @@ for (const reporter of reporters) {
})]
})

for (let i = 0; i < 1; i++) {
for (let type of Object.keys(consola.types).sort()) {
consola[type](`A message with consola.${type}()`)
}

consola.info('A JSON Log:', {
name: 'Cat',
color: '#454545'
for (let type of Object.keys(consola.types).sort()) {
consola[type](`A message with consola.${type}()`)
}

consola.info('A JSON Log:', {
name: 'Cat',
color: '#454545'
})

if (reporter === 'FancyReporter') {
consola.success({
message: 'This is a fancy badge',
additional: 'With some additional info',
additionalColor: 'brown',
badge: true
})
}

if (reporter === 'FancyReporter') {
consola.success({
message: 'This is a fancy badge',
additional: 'With some additional info',
additionalColor: 'brown',
badge: true
})
}

consola.error(new Error('Something bad happened!'))

const tagged = consola.create({ defaults: { tag: 'tagged' } })
for (let type of Object.keys(consola.types).sort()) {
tagged[type](`A tagged message with consola.${type}()`)
}

if (reporter === 'FancyReporter') {
tagged.success({
message: 'This is a fancy badge',
additional: 'With some additional info',
additionalColor: 'brown',
badge: true
})
}
consola.error(new Error('Something bad happened!'))

const tagged = consola.create({ defaults: { tag: 'tagged' } })
for (let type of Object.keys(consola.types).sort()) {
tagged[type](`A tagged message with consola.${type}()`)
}

if (reporter === 'FancyReporter') {
tagged.success({
message: 'This is a fancy badge',
additional: 'With some additional info',
additionalColor: 'brown',
badge: true
})
}
}
34 changes: 17 additions & 17 deletions src/reporters/fancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ export default class FancyReporter extends BasicReporter {
/* eslint-disable no-multi-spaces */
default: '' +
'%1$s' + // use text color
'%12$*-13$s' + // print icon with right padded space if exists
'%2$s' + // end text color
'%9$s' + // print tag
'%10$*-11$s' + // print icon with right padded space if exists
'%4$s' + // end text color
'%7$s' + // print tag
'%1$s' + // use text color (tags separator reset to white)
'%10$s' + // print log message
'%2$s' + // end text color
'%3$s' + // use additional text color
'%11$s' + // print additional arguments
'%8$s' + // print log message
'%4$s' + // end text color
'%2$s' + // use additional text color
'%9$s' + // print additional arguments
'%4$s' + // end additional text color
'\n',
badge: '\n' +
'%5$s' + // use background color
' %8$s ' + // log type with spacing
'%6$s' + // end background color
'%3$s' + // use background color
' %6$s ' + // log type with spacing
'%4$s' + // end background color
' ' +
'%1$s' + // use text color
'%9$s' + // print tag
'%10$s' + // print log message
'%2$s' + // end text color
'%7$s' + // print tag
'%8$s' + // print log message
'%4$s' + // end text color
'\n' +
'%3$s' + // use additional text color
'%11$s' + // print additional arguments
'%2$s' + // use additional text color
'%9$s' + // print additional arguments
'%4$s' + // end additional text color
'\n\n'
/* eslint-enable no-multi-spaces */
Expand Down Expand Up @@ -100,8 +100,8 @@ export default class FancyReporter extends BasicReporter {

const argv = []
// textColor=%1,%2 additionalColor=%3,%4 and bgColor=%5,%6
Array.prototype.push.apply(argv, this._colorCache[logObj.color])
Array.prototype.push.apply(argv, this._colorCache[logObj.additionalColor || 'grey'])
argv.push(this._colorCache[logObj.color][0])
argv.push(this._colorCache[logObj.additionalColor || 'grey'][0])
Array.prototype.push.apply(argv, this._colorCache[bgColorKey])

const icon = fields.type === 'log' ? '' : logObj.icon || ICONS[fields.type] || ICONS.default
Expand Down

0 comments on commit d213634

Please sign in to comment.