Skip to content

Commit d213634

Browse files
committed
fix: only one color ending parameter is enough
1 parent 2afb025 commit d213634

File tree

3 files changed

+64
-68
lines changed

3 files changed

+64
-68
lines changed

README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,16 @@ The following variables are supported:
168168

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

184182
```js
185183
consola = new Consola({
@@ -189,15 +187,15 @@ consola = new Consola({
189187
}),
190188
new FancyReporter({
191189
formats: {
192-
default: '[%7$s] [%8$-7s] %9$s%10$s%11$s\n', // same format as BasicReporter
190+
default: '[%5$s] [%6$-7s] %7$s%8$s%9$s\n', // same format as BasicReporter
193191
badge: '\n' +
194192
' /================================================\\\n' +
195-
' |%5$s' + '%12$s'.repeat(48) + '%6$s|\n' +
196-
' |%5$s%12$s' + ' '.repeat(46) + '%12$s%6$s|\n' +
197-
' |%5$s%12$s %8$-44s %12$s%6$s|\n' +
198-
' |%5$s%12$s %10$-44s %12$s%6$s|\n' +
199-
' |%5$s%12$s' + ' '.repeat(46) + '%12$s%6$s|\n' +
200-
' |%5$s' + '%12$s'.repeat(48) + '%6$s|\n' +
193+
' |%3$s' + '%10$s'.repeat(48) + '%4$s|\n' +
194+
' |%3$s%10$s' + ' '.repeat(46) + '%10$s%4$s|\n' +
195+
' |%3$s%10$s %6$-44s %10$s%4$s|\n' +
196+
' |%3$s%10$s %8$-44s %10$s%4$s|\n' +
197+
' |%3$s%10$s' + ' '.repeat(46) + '%10$s%4$s|\n' +
198+
' |%3$s' + '%10$s'.repeat(48) + '%4$s|\n' +
201199
' \\================================================/\n\n'
202200
}
203201
})

demo/index.js

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,37 @@ for (const reporter of reporters) {
1919
})]
2020
})
2121

22-
for (let i = 0; i < 1; i++) {
23-
for (let type of Object.keys(consola.types).sort()) {
24-
consola[type](`A message with consola.${type}()`)
25-
}
26-
27-
consola.info('A JSON Log:', {
28-
name: 'Cat',
29-
color: '#454545'
22+
for (let type of Object.keys(consola.types).sort()) {
23+
consola[type](`A message with consola.${type}()`)
24+
}
25+
26+
consola.info('A JSON Log:', {
27+
name: 'Cat',
28+
color: '#454545'
29+
})
30+
31+
if (reporter === 'FancyReporter') {
32+
consola.success({
33+
message: 'This is a fancy badge',
34+
additional: 'With some additional info',
35+
additionalColor: 'brown',
36+
badge: true
3037
})
38+
}
3139

32-
if (reporter === 'FancyReporter') {
33-
consola.success({
34-
message: 'This is a fancy badge',
35-
additional: 'With some additional info',
36-
additionalColor: 'brown',
37-
badge: true
38-
})
39-
}
40-
41-
consola.error(new Error('Something bad happened!'))
42-
43-
const tagged = consola.create({ defaults: { tag: 'tagged' } })
44-
for (let type of Object.keys(consola.types).sort()) {
45-
tagged[type](`A tagged message with consola.${type}()`)
46-
}
47-
48-
if (reporter === 'FancyReporter') {
49-
tagged.success({
50-
message: 'This is a fancy badge',
51-
additional: 'With some additional info',
52-
additionalColor: 'brown',
53-
badge: true
54-
})
55-
}
40+
consola.error(new Error('Something bad happened!'))
41+
42+
const tagged = consola.create({ defaults: { tag: 'tagged' } })
43+
for (let type of Object.keys(consola.types).sort()) {
44+
tagged[type](`A tagged message with consola.${type}()`)
45+
}
46+
47+
if (reporter === 'FancyReporter') {
48+
tagged.success({
49+
message: 'This is a fancy badge',
50+
additional: 'With some additional info',
51+
additionalColor: 'brown',
52+
badge: true
53+
})
5654
}
5755
}

src/reporters/fancy.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,28 @@ export default class FancyReporter extends BasicReporter {
3939
/* eslint-disable no-multi-spaces */
4040
default: '' +
4141
'%1$s' + // use text color
42-
'%12$*-13$s' + // print icon with right padded space if exists
43-
'%2$s' + // end text color
44-
'%9$s' + // print tag
42+
'%10$*-11$s' + // print icon with right padded space if exists
43+
'%4$s' + // end text color
44+
'%7$s' + // print tag
4545
'%1$s' + // use text color (tags separator reset to white)
46-
'%10$s' + // print log message
47-
'%2$s' + // end text color
48-
'%3$s' + // use additional text color
49-
'%11$s' + // print additional arguments
46+
'%8$s' + // print log message
47+
'%4$s' + // end text color
48+
'%2$s' + // use additional text color
49+
'%9$s' + // print additional arguments
5050
'%4$s' + // end additional text color
5151
'\n',
5252
badge: '\n' +
53-
'%5$s' + // use background color
54-
' %8$s ' + // log type with spacing
55-
'%6$s' + // end background color
53+
'%3$s' + // use background color
54+
' %6$s ' + // log type with spacing
55+
'%4$s' + // end background color
5656
' ' +
5757
'%1$s' + // use text color
58-
'%9$s' + // print tag
59-
'%10$s' + // print log message
60-
'%2$s' + // end text color
58+
'%7$s' + // print tag
59+
'%8$s' + // print log message
60+
'%4$s' + // end text color
6161
'\n' +
62-
'%3$s' + // use additional text color
63-
'%11$s' + // print additional arguments
62+
'%2$s' + // use additional text color
63+
'%9$s' + // print additional arguments
6464
'%4$s' + // end additional text color
6565
'\n\n'
6666
/* eslint-enable no-multi-spaces */
@@ -100,8 +100,8 @@ export default class FancyReporter extends BasicReporter {
100100

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

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

0 commit comments

Comments
 (0)