UNPKG

2.31 kBMarkdownView Raw
1# Colorful
2
3It's not just color, it's everything colorful in terminal.
4
5---------------------
6
7# Color
8
9Color in terminal and only terminal.
10
11## Programmer
12
13As a programmer, you think they are functions:
14
15```javascript
16var color = require('colorful').color
17color.red('hello')
18color.underline('hello')
19color.red(color.underline('hello'))
20```
21
22## Human
23
24As a human, you think you are a painter:
25
26```javascript
27var paint = require('colorful').paint
28paint('hello').red.color
29paint('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
35paint('hello').bold.underline.red.style
36```
37
38## Alien
39
40As an alien, you are from outer space, you think it should be:
41
42```javascript
43require('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
51As a detective, you think we should detect if color is supported:
52
53```javascript
54require('colorful').isSupported
55
56// we can disable color
57require('colorful').disabled = true
58require('colorful').isSupported
59// => false
60```
61
62------
63
64# Logging
65
66Colorful 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
72Default is my favorite, we should do nothing:
73
74```javascript
75var logging = require('colorful').logging;
76// start a nested logging
77logging.start('Start Application')
78logging.info('send an info message')
79
80// start another nested logging
81logging.start('Start subprocess')
82logging.warn('send a warn message')
83logging.end('End subprocess')
84
85logging.error('send an error message')
86logging.debug('send a debug message')
87logging.end('End Application')
88```
89
90## Config
91
92I want to show debug message:
93
94```javascript
95logging.config('debug')
96// or
97logging.config({level: 'debug'})
98logging.config({verbose: true})
99```
100
101## Scheme
102
103Define your logging scheme:
104
105```javascript
106var 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}
131logging.scheme = scheme;
132```