-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcols.js
72 lines (61 loc) · 1.83 KB
/
cols.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
70
71
72
'use strict';
// ==================================================================================
// draw.js
// ----------------------------------------------------------------------------------
// Description: tiny CLI draw library
// for Node.js
// Copyright: (c) 2016
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// inspired by: https://github.com/jbnicolai/ansi-256-colors
// Contributors: -
// ----------------------------------------------------------------------------------
// License: MIT
// ==================================================================================
let fgcodes = Array.apply(null, new Array(256)).map(function (_, i) { return '\x1b[38;5;' + i + 'm'; });
let fg_rgb = fgcodes.slice(16, 232);
let fg_gray = fgcodes.slice(232, 256);
let bgcodes = Array.apply(null, new Array(256)).map(function (_, i) { return '\x1b[48;5;' + i + 'm'; });
let bg_rgb = bgcodes.slice(16, 232);
let bg_gray = bgcodes.slice(232, 256);
let reset_str = '\x1b[0m';
let colors = {
black: 0,
red: 1,
green: 41,
blue: 26,
yellow: 222,
brown: 130,
gray: 240,
lightgray: 246,
darkgray: 234,
white: 15
};
function f(g) {
return fgcodes[g];
}
exports.f = f;
exports.fg = function(r, g, b) {
return fg_rgb[36*r + 6*g + b];
};
exports.fgg = function(g) {
return fg_gray[g];
};
function b(g) {
return bgcodes[g];
}
exports.b = b;
exports.bg = function(r, g, b) {
return bg_rgb[36*r + 6*g + b];
};
exports.bgg = function(g) {
return bg_gray[g];
};
exports.reset = function() {
return reset_str
} ;
// defaults
exports.log = function(str, fg, bg) {
let color = (fg != '' ? fgcodes[(typeof fg === 'string') ? colors[fg] : fg] : '') + (bg ? bgcodes[(typeof bg === 'string') ? colors[bg] : bg] : '');
return color + str + reset_str;
};