@@ -2,7 +2,7 @@ import stringWidth from 'string-width'
2
2
import figures from 'figures'
3
3
import BasicReporter from './basic'
4
4
import { parseStack } from '../utils/error'
5
- import { chalkColor } from '../utils/chalk'
5
+ import { chalkColor , chalkBgColor } from '../utils/chalk'
6
6
import { TYPE_COLOR_MAP , LEVEL_COLOR_MAP } from '../utils/fancy'
7
7
8
8
const DEFAULTS = {
@@ -30,22 +30,33 @@ export default class FancyReporter extends BasicReporter {
30
30
}
31
31
32
32
typeColor ( type , level ) {
33
- return chalkColor ( TYPE_COLOR_MAP [ type ] || LEVEL_COLOR_MAP [ level ] || this . options . secondaryColor )
33
+ return chalkColor ( )
34
34
}
35
35
36
- formatType ( type , typeColor ) {
37
- const _type = typeof TYPE_ICONS [ type ] === 'string' ? TYPE_ICONS [ type ] : type
38
- return _type ? typeColor ( _type ) : ''
36
+ formatType ( logObj , isBadge ) {
37
+ const typeColor = TYPE_COLOR_MAP [ logObj . type ] ||
38
+ LEVEL_COLOR_MAP [ logObj . level ] ||
39
+ this . options . secondaryColor
40
+
41
+ if ( isBadge ) {
42
+ return chalkBgColor ( typeColor ) . black ( ` ${ logObj . type . toUpperCase ( ) } ` )
43
+ }
44
+
45
+ const _type = typeof TYPE_ICONS [ logObj . type ] === 'string' ? TYPE_ICONS [ logObj . type ] : logObj . type
46
+ return _type ? chalkColor ( typeColor ) ( _type ) : ''
39
47
}
40
48
41
49
formatLogObj ( logObj , { width } ) {
42
50
const { message, additional } = this . formatArgs ( logObj . args )
43
51
44
- const typeColor = this . typeColor ( logObj . type , logObj . level )
52
+ const isBadge = logObj . badge || logObj . level < 2
53
+
45
54
const secondaryColor = chalkColor ( this . options . secondaryColor )
46
55
47
56
const date = secondaryColor ( this . formatDate ( logObj . date ) )
48
- const type = this . formatType ( logObj . type , typeColor )
57
+
58
+ const type = this . formatType ( logObj , isBadge )
59
+
49
60
const tag = logObj . tag ? secondaryColor ( logObj . tag ) : ''
50
61
51
62
let left = this . filterAndJoin ( [ type , message ] )
@@ -59,6 +70,6 @@ export default class FancyReporter extends BasicReporter {
59
70
? secondaryColor ( '\n' + additional )
60
71
: ''
61
72
62
- return line
73
+ return isBadge ? '\n' + line + '\n' : line
63
74
}
64
75
}
0 commit comments