forked from supercoolpeople/hatchjs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcolors.js
More file actions
90 lines (79 loc) · 2.28 KB
/
Copy pathcolors.js
File metadata and controls
90 lines (79 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// Hatch.js is a CMS and social website building framework built in Node.js
// Copyright (C) 2013 Inventures Software Ltd
//
// This file is part of Hatch.js
//
// Hatch.js is free software: you can redistribute it and/or modify it under the terms of the
// GNU Affero General Public License as published by the Free Software Foundation, version 3
//
// Hatch.js is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Affero General Public License for more details. You should have received a copy of the GNU
// General Public License along with Hatch.js. If not, see <http://www.gnu.org/licenses/>.
//
// Authors: Marcus Greenwood, Anatoliy Chakkaev and others
//
var util = require('util');
var colors = {
'bold' : [1, 22],
'italic' : [3, 23],
'underline' : [4, 24],
'inverse' : [7, 27],
'white' : [37, 39],
'grey' : [90, 39],
'black' : [30, 39],
'blue' : [34, 39],
'cyan' : [36, 39],
'green' : [32, 39],
'magenta' : [35, 39],
'red' : [31, 39],
'yellow' : [33, 39]
};
var colorNames = Object.keys(colors);
exports.styles = {
'special': 'cyan',
'number': 'yellow',
'boolean': 'yellow',
'undefined': 'grey',
'null': 'bold',
'string': 'green',
'date': 'magenta',
'regexp': 'red'
};
function stylize(str, styleType) {
var style = exports.styles[styleType];
if (style) {
return colorize(str, style);
} else {
return str;
}
}
function colorize(str, color) {
var code = colors[color];
if (!code) return str;
return '\u001b[' + code[0] + 'm' + str +
'\u001b[' + code[1] + 'm';
};
exports.stylize = stylize;
exports.colorize = colorize;
exports.$ = function $(str) {
str = new(String)(str);
colorNames.forEach(function (name) {
Object.defineProperty(str, name, {
get: function () {
return $(colorize(this, name));
}
});
});
return str;
};
var time = Date.now();
var timing = process.env.TIMING;
exports.$.puts = function () {
util.puts((timing ? Date.now() - time + ' ' : '') + [].join.call(arguments, ' '));
if (timing === 'relative') {
time = Date.now();
}
};