1
1
import stringWidth from "string-width" ;
2
2
import { mainSymbols } from "figures" ;
3
- import chalk from "chalk " ;
3
+ import * as colors from "colorette " ;
4
4
import { parseStack } from "../utils/error" ;
5
- import { chalkColor , chalkBgColor } from "../utils/chalk" ;
6
5
import { TYPE_COLOR_MAP , LEVEL_COLOR_MAP } from "../utils/fancy" ;
7
6
import BasicReporter from "./basic" ;
8
7
@@ -29,18 +28,15 @@ export default class FancyReporter extends BasicReporter {
29
28
}
30
29
31
30
formatStack ( stack ) {
32
- const grey = chalkColor ( "grey" ) ;
33
- const cyan = chalkColor ( "cyan" ) ;
34
-
35
31
return (
36
32
"\n" +
37
33
parseStack ( stack )
38
34
. map (
39
35
( line ) =>
40
36
" " +
41
37
line
42
- . replace ( / ^ a t + / , ( m ) => grey ( m ) )
43
- . replace ( / \( ( .+ ) \) / , ( _ , m ) => `(${ cyan ( m ) } )` )
38
+ . replace ( / ^ a t + / , ( m ) => colors . gray ( m ) )
39
+ . replace ( / \( ( .+ ) \) / , ( _ , m ) => `(${ colors . cyan ( m ) } )` )
44
40
)
45
41
. join ( "\n" )
46
42
) ;
@@ -53,14 +49,16 @@ export default class FancyReporter extends BasicReporter {
53
49
this . options . secondaryColor ;
54
50
55
51
if ( isBadge ) {
56
- return chalkBgColor ( typeColor ) . black ( ` ${ logObj . type . toUpperCase ( ) } ` ) ;
52
+ return getBgColor ( typeColor ) (
53
+ colors . black ( ` ${ logObj . type . toUpperCase ( ) } ` )
54
+ ) ;
57
55
}
58
56
59
57
const _type =
60
58
typeof TYPE_ICONS [ logObj . type ] === "string"
61
59
? TYPE_ICONS [ logObj . type ]
62
60
: logObj . icon || logObj . type ;
63
- return _type ? chalkColor ( typeColor ) ( _type ) : "" ;
61
+ return _type ? getColor ( typeColor ) ( _type ) : "" ;
64
62
}
65
63
66
64
formatLogObj ( logObj , { width } ) {
@@ -71,7 +69,7 @@ export default class FancyReporter extends BasicReporter {
71
69
? Boolean ( logObj . badge )
72
70
: logObj . level < 2 ;
73
71
74
- const secondaryColor = chalkColor ( this . options . secondaryColor ) ;
72
+ const secondaryColor = getColor ( this . options . secondaryColor ) ;
75
73
76
74
const date = this . formatDate ( logObj . date ) ;
77
75
const coloredDate = date && secondaryColor ( date ) ;
@@ -81,7 +79,7 @@ export default class FancyReporter extends BasicReporter {
81
79
const tag = logObj . tag ? secondaryColor ( logObj . tag ) : "" ;
82
80
83
81
const formattedMessage = message . replace ( / ` ( [ ^ ` ] + ) ` / g, ( _ , m ) =>
84
- chalk . cyan ( m )
82
+ colors . cyan ( m )
85
83
) ;
86
84
87
85
let line ;
@@ -96,3 +94,14 @@ export default class FancyReporter extends BasicReporter {
96
94
return isBadge ? "\n" + line + "\n" : line ;
97
95
}
98
96
}
97
+
98
+ function getColor ( color : string ) {
99
+ return ( colors as any ) [ color ] || colors . white ;
100
+ }
101
+
102
+ function getBgColor ( color : string ) {
103
+ return (
104
+ ( colors as any ) [ `bg${ color [ 0 ] . toUpperCase ( ) } ${ color . slice ( 1 ) } ` ] ||
105
+ colors . bgWhite
106
+ ) ;
107
+ }
0 commit comments