Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 167 lines (120 sloc) 3.19 kb
1f617ec @pksunkara Reverted to the latest tag
pksunkara authored
1 # colors.js
8b3d411 @Marak added docs
authored
2
dfb15b5 @Marak [refactor] [major] Code cleanup. Node has changed a bit since 2010.
authored
3 ## get color and style in your node.js console
4
1f617ec @pksunkara Reverted to the latest tag
pksunkara authored
5 <img src="https://github.com/Marak/colors.js/raw/master/screenshots/colors.png"/>
731b73f @Marak update docs
authored
6
e4decd0 @Marak [api] Added custom themes using colors.setTheme. Cleaned up browser dete...
authored
7 ## Installation
8
936cf56 @Marak [minor] [fix] Add defaults for .trap and .zalgo. .random now using corre...
authored
9 npm install colors
e4decd0 @Marak [api] Added custom themes using colors.setTheme. Cleaned up browser dete...
authored
10
11 ## colors and styles!
12
dfb15b5 @Marak [refactor] [major] Code cleanup. Node has changed a bit since 2010.
authored
13 ### text colors
14
15 - black
16 - red
17 - green
18 - yellow
19 - blue
20 - magenta
21 - cyan
22 - white
23 - gray
24 - grey
25
26 ### background colors
27
28
29
30 - bgBlack
31 - bgRed
32 - bgGreen
33 - bgYellow
34 - bgBlue
35 - bgMagenta
36 - bgCyan
37 - bgWhite
38
39 ### styles
40
41 - reset
42 - bold
43 - dim
44 - italic
45 - underline
46 - inverse
47 - hidden
48 - strikethrough
49
50 ### extras
51
52 - rainbow
53 - zebra
54 - america
55 - trap
56 - random
57
e4decd0 @Marak [api] Added custom themes using colors.setTheme. Cleaned up browser dete...
authored
58
59 ## Usage
60
dfb15b5 @Marak [refactor] [major] Code cleanup. Node has changed a bit since 2010.
authored
61 By popular demand, `colors` now ships with two types of usages!
62
63 The super nifty way
64
65 ```js
936cf56 @Marak [minor] [fix] Add defaults for .trap and .zalgo. .random now using corre...
authored
66 var colors = require('colors');
e4decd0 @Marak [api] Added custom themes using colors.setTheme. Cleaned up browser dete...
authored
67
68 console.log('hello'.green); // outputs green text
69 console.log('i like cake and pies'.underline.red) // outputs red underlined text
70 console.log('inverse the color'.inverse); // inverses the color
dfb15b5 @Marak [refactor] [major] Code cleanup. Node has changed a bit since 2010.
authored
71 console.log('OMG Rainbows!'.rainbow); // rainbow
72 console.log('Run the trap'.trap); // Drops the bass
73
74 ```
75
76 or a slightly less nifty way which doesn't extend `String.prototype`
77
78 ```js
79 var colors = require('colors/safe');
80
81 console.log(colors.green('hello')); // outputs green text
82 console.log(colors.red.underline('i like cake and pies')) // outputs red underlined text
83 console.log(colors.inverse('inverse the color')); // inverses the color
84 console.log(colors.rainbow('OMG Rainbows!')); // rainbow
85 console.log(colors.trap('Run the trap')); // Drops the bass
86
87 ```
88
89 I prefer the first way. Some people seem to be afraid of extending `String.prototype` and prefer the second way.
90
91 If you are writing good code you will never have an issue with the first approach. If you really don't want to touch `String.prototype`, the second usage will not touch `String` native object.
92
93 ## Disabling Colors
94
95 To disable colors you can pass the following arguments in the command line to your application:
96
97 ```bash
98 node myapp.js --no-color
e4decd0 @Marak [api] Added custom themes using colors.setTheme. Cleaned up browser dete...
authored
99 ```
100
3968ec6 @Marak [dist] Release v1.0.0
authored
101 ## Console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data)
102
cfad32b @Marak [dist] Release v1.0.1
authored
103 ```js
3968ec6 @Marak [dist] Release v1.0.0
authored
104 var name = 'Marak';
f821fd0 @kahwee Changed chalk to colors in example
kahwee authored
105 console.log(colors.green('Hello %s'), name);
3968ec6 @Marak [dist] Release v1.0.0
authored
106 // outputs -> 'Hello Marak'
fee9d24 @Marak [docs] Update README
authored
107 ```
3968ec6 @Marak [dist] Release v1.0.0
authored
108
dfb15b5 @Marak [refactor] [major] Code cleanup. Node has changed a bit since 2010.
authored
109 ## Custom themes
110
111 ### Using standard API
e4decd0 @Marak [api] Added custom themes using colors.setTheme. Cleaned up browser dete...
authored
112
113 ```js
114
75858e0 @Marak [docs] Fixed example in docs
authored
115 var colors = require('colors');
e4decd0 @Marak [api] Added custom themes using colors.setTheme. Cleaned up browser dete...
authored
116
117 colors.setTheme({
118 silly: 'rainbow',
119 input: 'grey',
120 verbose: 'cyan',
121 prompt: 'grey',
122 info: 'green',
123 data: 'grey',
124 help: 'cyan',
125 warn: 'yellow',
126 debug: 'blue',
127 error: 'red'
128 });
129
130 // outputs red text
131 console.log("this is an error".error);
132
133 // outputs yellow text
134 console.log("this is a warning".warn);
135 ```
136
dfb15b5 @Marak [refactor] [major] Code cleanup. Node has changed a bit since 2010.
authored
137 ### Using string safe API
e4decd0 @Marak [api] Added custom themes using colors.setTheme. Cleaned up browser dete...
authored
138
dfb15b5 @Marak [refactor] [major] Code cleanup. Node has changed a bit since 2010.
authored
139 ```js
140 var colors = require('colors/safe');
a58b5d2 @Marak added docs
authored
141
dfb15b5 @Marak [refactor] [major] Code cleanup. Node has changed a bit since 2010.
authored
142 // set single property
143 var error = colors.red;
144 error('this is red');
ba56520 @Marak updating docs
authored
145
dfb15b5 @Marak [refactor] [major] Code cleanup. Node has changed a bit since 2010.
authored
146 // set theme
147 colors.setTheme({
148 silly: 'rainbow',
149 input: 'grey',
150 verbose: 'cyan',
151 prompt: 'grey',
152 info: 'green',
153 data: 'grey',
154 help: 'cyan',
155 warn: 'yellow',
156 debug: 'blue',
157 error: 'red'
158 });
159
160 // outputs red text
161 console.log(colors.error("this is an error"));
162
163 // outputs yellow text
164 console.log(colors.warn("this is a warning"));
165 ```
b5bd041 @Marak updating docs
authored
166
1f617ec @pksunkara Reverted to the latest tag
pksunkara authored
167 *Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.*
Something went wrong with that request. Please try again.