@@ -5,24 +5,51 @@ function rgb(r, g, b) {
55 return style . color . ansi256 . rgb ( r , g , b ) ;
66}
77
8- var colors = {
9- black : rgb ( 0 , 0 , 0 ) ,
10- blue : rgb ( 0 , 0 , 255 ) ,
11- cyan : rgb ( 0 , 255 , 255 ) ,
12- green : rgb ( 0 , 255 , 0 ) ,
13- magenta : rgb ( 255 , 0 , 255 ) ,
14- red : rgb ( 255 , 0 , 0 ) ,
15- white : rgb ( 255 , 255 , 255 ) ,
16- yellow : rgb ( 255 , 255 , 0 )
8+ var THEMES = {
9+ 'default' : {
10+ black : rgb ( 0 , 0 , 0 ) ,
11+ blue : rgb ( 0 , 0 , 255 ) ,
12+ cyan : rgb ( 0 , 255 , 255 ) ,
13+ green : rgb ( 0 , 255 , 0 ) ,
14+ magenta : rgb ( 255 , 0 , 255 ) ,
15+ red : rgb ( 255 , 0 , 0 ) ,
16+ white : rgb ( 255 , 255 , 255 ) ,
17+ yellow : rgb ( 255 , 255 , 0 )
18+ } ,
19+ 'dark' : {
20+ black : rgb ( 0 , 0 , 0 ) ,
21+ blue : rgb ( 0 , 0 , 153 ) ,
22+ cyan : rgb ( 0 , 153 , 153 ) ,
23+ green : rgb ( 0 , 153 , 0 ) ,
24+ magenta : rgb ( 153 , 0 , 153 ) ,
25+ red : rgb ( 153 , 0 , 0 ) ,
26+ white : rgb ( 255 , 255 , 255 ) ,
27+ yellow : rgb ( 153 , 153 , 0 )
28+ } ,
29+ 'pink' : {
30+ black : rgb ( 0 , 0 , 0 ) ,
31+ blue : rgb ( 0 , 0 , 153 ) ,
32+ cyan : rgb ( 0 , 153 , 153 ) ,
33+ green : rgb ( 255 , 20 , 147 ) ,
34+ magenta : rgb ( 153 , 0 , 153 ) ,
35+ red : rgb ( 220 , 20 , 60 ) ,
36+ white : rgb ( 255 , 255 , 255 ) ,
37+ yellow : rgb ( 255 , 69 , 0 )
38+ }
1739} ;
1840
1941var chalk = {
20- enabled : true
42+ enabled : true ,
43+ theme : THEMES . default
2144} ;
2245
2346var pres = [ ] ;
2447var posts = [ ] ;
2548
49+ chalk . setTheme = function ( name ) {
50+ this . theme = THEMES [ name ] || THEMES . default ;
51+ } ;
52+
2653chalk . print = function ( s ) {
2754 s = this . enabled ? pres . join ( '' ) + s + posts . join ( '' ) : s ;
2855 pres . length = posts . length = 0 ;
@@ -43,7 +70,7 @@ _.chain(['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'])
4370. each ( function ( color ) {
4471 Object . defineProperty ( chalk , color , {
4572 get : function ( ) {
46- return chalk . wrap ( colors [ color ] , style . color . close ) ;
73+ return chalk . wrap ( chalk . theme [ color ] , style . color . close ) ;
4774 }
4875 } ) ;
4976} ) ;
0 commit comments