@@ -5,24 +5,51 @@ function rgb(r, g, b) {
5
5
return style . color . ansi256 . rgb ( r , g , b ) ;
6
6
}
7
7
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
+ }
17
39
} ;
18
40
19
41
var chalk = {
20
- enabled : true
42
+ enabled : true ,
43
+ theme : THEMES . default
21
44
} ;
22
45
23
46
var pres = [ ] ;
24
47
var posts = [ ] ;
25
48
49
+ chalk . setTheme = function ( name ) {
50
+ this . theme = THEMES [ name ] || THEMES . default ;
51
+ } ;
52
+
26
53
chalk . print = function ( s ) {
27
54
s = this . enabled ? pres . join ( '' ) + s + posts . join ( '' ) : s ;
28
55
pres . length = posts . length = 0 ;
@@ -43,7 +70,7 @@ _.chain(['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'])
43
70
. each ( function ( color ) {
44
71
Object . defineProperty ( chalk , color , {
45
72
get : function ( ) {
46
- return chalk . wrap ( colors [ color ] , style . color . close ) ;
73
+ return chalk . wrap ( chalk . theme [ color ] , style . color . close ) ;
47
74
}
48
75
} ) ;
49
76
} ) ;
0 commit comments