11import stringWidth from "string-width" ;
22import { mainSymbols } from "figures" ;
3- import chalk from "chalk " ;
3+ import * as colors from "colorette " ;
44import { parseStack } from "../utils/error" ;
5- import { chalkColor , chalkBgColor } from "../utils/chalk" ;
65import { TYPE_COLOR_MAP , LEVEL_COLOR_MAP } from "../utils/fancy" ;
76import BasicReporter from "./basic" ;
87
@@ -29,18 +28,15 @@ export default class FancyReporter extends BasicReporter {
2928 }
3029
3130 formatStack ( stack ) {
32- const grey = chalkColor ( "grey" ) ;
33- const cyan = chalkColor ( "cyan" ) ;
34-
3531 return (
3632 "\n" +
3733 parseStack ( stack )
3834 . map (
3935 ( line ) =>
4036 " " +
4137 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 ) } )` )
4440 )
4541 . join ( "\n" )
4642 ) ;
@@ -53,14 +49,16 @@ export default class FancyReporter extends BasicReporter {
5349 this . options . secondaryColor ;
5450
5551 if ( isBadge ) {
56- return chalkBgColor ( typeColor ) . black ( ` ${ logObj . type . toUpperCase ( ) } ` ) ;
52+ return getBgColor ( typeColor ) (
53+ colors . black ( ` ${ logObj . type . toUpperCase ( ) } ` )
54+ ) ;
5755 }
5856
5957 const _type =
6058 typeof TYPE_ICONS [ logObj . type ] === "string"
6159 ? TYPE_ICONS [ logObj . type ]
6260 : logObj . icon || logObj . type ;
63- return _type ? chalkColor ( typeColor ) ( _type ) : "" ;
61+ return _type ? getColor ( typeColor ) ( _type ) : "" ;
6462 }
6563
6664 formatLogObj ( logObj , { width } ) {
@@ -71,7 +69,7 @@ export default class FancyReporter extends BasicReporter {
7169 ? Boolean ( logObj . badge )
7270 : logObj . level < 2 ;
7371
74- const secondaryColor = chalkColor ( this . options . secondaryColor ) ;
72+ const secondaryColor = getColor ( this . options . secondaryColor ) ;
7573
7674 const date = this . formatDate ( logObj . date ) ;
7775 const coloredDate = date && secondaryColor ( date ) ;
@@ -81,7 +79,7 @@ export default class FancyReporter extends BasicReporter {
8179 const tag = logObj . tag ? secondaryColor ( logObj . tag ) : "" ;
8280
8381 const formattedMessage = message . replace ( / ` ( [ ^ ` ] + ) ` / g, ( _ , m ) =>
84- chalk . cyan ( m )
82+ colors . cyan ( m )
8583 ) ;
8684
8785 let line ;
@@ -96,3 +94,14 @@ export default class FancyReporter extends BasicReporter {
9694 return isBadge ? "\n" + line + "\n" : line ;
9795 }
9896}
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