@@ -50,12 +50,25 @@ chalk.wrap = function(pre, post) {
5050 return f ;
5151} ;
5252
53+ function bgName ( s ) { return 'bg' + s [ 0 ] . toUpperCase ( ) + s . substr ( 1 ) ; }
54+
5355chalk . init = function ( ) {
54- var h = require ( './helper' ) ;
55- _ . each ( h . getCodeDirData ( 'colors' ) , function ( f ) {
56- chalk . themes [ f . name ] = _ . mapObject ( f . data , function ( v , k ) {
57- return chalk . use256 ? style . color . ansi256 . hex ( v ) : style . color . ansi . hex ( v ) ;
56+ _ . each ( require ( './helper' ) . getCodeDirData ( 'colors' ) , function ( f ) {
57+ var o = { } ;
58+ _ . pairs ( f . data ) . forEach ( function ( x ) {
59+ var k = x [ 0 ] ;
60+ var v = x [ 1 ] ;
61+ var bgK = bgName ( k ) ;
62+
63+ if ( chalk . use256 ) {
64+ o [ k ] = style . color . ansi256 . hex ( v ) ;
65+ o [ bgK ] = style . bgColor . ansi256 . hex ( v ) ;
66+ } else {
67+ o [ k ] = style . color . ansi . hex ( v ) ;
68+ o [ bgK ] = style . bgColor . ansi . hex ( v ) ;
69+ }
5870 } ) ;
71+ chalk . themes [ f . name ] = o ;
5972 } ) ;
6073
6174 _ . chain ( [ 'black' , 'blue' , 'cyan' , 'gray' , 'green' , 'magenta' , 'red' , 'white' , 'yellow' ] )
@@ -66,6 +79,13 @@ chalk.init = function() {
6679 } ,
6780 configurable : true
6881 } ) ;
82+ var bgcolor = bgName ( color ) ;
83+ Object . defineProperty ( chalk , bgcolor , {
84+ get : function ( ) {
85+ return chalk . wrap ( chalk . theme [ bgcolor ] , style . bgColor . close ) ;
86+ } ,
87+ configurable : true
88+ } ) ;
6989 } ) ;
7090
7191 _ . chain ( [ 'bold' , 'dim' , 'italic' , 'inverse' , 'strikethrough' , 'underline' ] )
0 commit comments