1 | # Colorful
|
2 |
|
3 | It's not just color, it's everything colorful in terminal.
|
4 |
|
5 | ---------------------
|
6 |
|
7 | # Color
|
8 |
|
9 | Color in terminal and only terminal.
|
10 |
|
11 | ## Programmer
|
12 |
|
13 | As a programmer, you think they are functions:
|
14 |
|
15 | ```javascript
|
16 | var color = require('colorful').color
|
17 | color.red('hello')
|
18 | color.underline('hello')
|
19 | color.red(color.underline('hello'))
|
20 | ```
|
21 |
|
22 | ## Human
|
23 |
|
24 | As a human, you think you are a painter:
|
25 |
|
26 | ```javascript
|
27 | var paint = require('colorful').paint
|
28 | paint('hello').red.color
|
29 | paint('hello').bold.underline.red.color
|
30 | ```
|
31 |
|
32 | **WTF**, is bold, underline a color? If you don't like the idea, try:
|
33 |
|
34 | ```javascript
|
35 | paint('hello').bold.underline.red.style
|
36 | ```
|
37 |
|
38 | ## Alien
|
39 |
|
40 | As an alien, you are from outer space, you think it should be:
|
41 |
|
42 | ```javascript
|
43 | require('colorful').colorful()
|
44 | 'hello'.to.red.color
|
45 | 'hello'.to.underline.bold.red.color
|
46 | 'hello'.to.underline.bold.red.style
|
47 | ```
|
48 |
|
49 | ## Detective
|
50 |
|
51 | As a detective, you think we should detect if color is supported:
|
52 |
|
53 | ```javascript
|
54 | require('colorful').isSupported
|
55 |
|
56 | // we can disable color
|
57 | require('colorful').disabled = true
|
58 | require('colorful').isSupported
|
59 | // => false
|
60 | ```
|
61 |
|
62 | ------
|
63 |
|
64 | # Logging
|
65 |
|
66 | Colorful and nested logging in terminal.
|
67 |
|
68 | [![nico](http://lab.lepture.com/nico/nico-look.png)](http://lab.lepture.com/nico/)
|
69 |
|
70 | ## Favorite
|
71 |
|
72 | Default is my favorite, we should do nothing:
|
73 |
|
74 | ```javascript
|
75 | var logging = require('colorful').logging;
|
76 | // start a nested logging
|
77 | logging.start('Start Application')
|
78 | logging.info('send an info message')
|
79 |
|
80 | // start another nested logging
|
81 | logging.start('Start subprocess')
|
82 | logging.warn('send a warn message')
|
83 | logging.end('End subprocess')
|
84 |
|
85 | logging.error('send an error message')
|
86 | logging.debug('send a debug message')
|
87 | logging.end('End Application')
|
88 | ```
|
89 |
|
90 | ## Config
|
91 |
|
92 | I want to show debug message:
|
93 |
|
94 | ```javascript
|
95 | logging.config('debug')
|
96 | // or
|
97 | logging.config({level: 'debug'})
|
98 | logging.config({verbose: true})
|
99 | ```
|
100 |
|
101 | ## Scheme
|
102 |
|
103 | Define your logging scheme:
|
104 |
|
105 | ```javascript
|
106 | var scheme = {
|
107 | debug: {
|
108 | start: '# ',
|
109 | color: 'gray',
|
110 | end: ' #'
|
111 | },
|
112 | info: {
|
113 | start: 'v ',
|
114 | color: 'green'
|
115 | },
|
116 | warn: {
|
117 | start: '! ',
|
118 | color: 'yellow'
|
119 | },
|
120 | error: {
|
121 | start: 'x ',
|
122 | color: 'red'
|
123 | },
|
124 | start: {
|
125 | start: '> '
|
126 | },
|
127 | end: {
|
128 | start: '< '
|
129 | }
|
130 | }
|
131 | logging.scheme = scheme;
|
132 | ```
|