-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
69 lines (56 loc) · 1.63 KB
/
index.js
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
/* vim:set ts=2 sw=2 sts=2 expandtab */
/*jshint asi: true newcap: true undef: true es5: true node: true devel: true
forin: false */
/*global define: true */
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
"use strict";
var ESC = '\u001b['
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
var SGR_STYLES = {
bold: [ 1, 22 ],
italic: [ 3, 23 ],
underline: [ 4, 24 ],
blink: [ 5, 25 ],
inverse: [ 7, 27 ],
frame: [ 51, 54 ],
encircle: [ 52, 54 ],
overline: [ 53, 55 ],
strikethrough: [ 53, 55 ]
}
var SGR_COLORS = {}
var SGR_BACKROUNDS = {}
var COLORS = [
'black',
'red',
'green',
'yellow',
'blue',
'magenta',
'cyan',
'white'
]
COLORS.forEach(function(color, index) {
SGR_COLORS[color] = [ 30 + index, 39 ]
SGR_BACKROUNDS[color] = [ 40 + index, 49 ]
})
function sgr(options, id, message) {
var params = options[id]
if (params) message = ESC + params[0] + 'm' + message + ESC + params[1] + 'm'
return message
}
exports.style = sgr.bind(null, SGR_STYLES)
exports.color = sgr.bind(null, SGR_COLORS)
exports.background = sgr.bind(null, SGR_BACKROUNDS)
Object.keys(SGR_STYLES).forEach(function(name) {
exports[name] = exports.style.bind(null, name)
})
Object.keys(SGR_COLORS).forEach(function(name) {
exports[name] = exports.color.bind(null, name)
exports['bg' + name] = exports.background.bind(null, name)
})
var index = 0
while(index++ < 256) {
SGR_COLORS[index] = ['38;5;' + index, 39]
SGR_BACKROUNDS[index] = ['48;5;' + index, 39]
}
});