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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
var bash_codes = exports.bash_codes = {
"BLACK" : {
"text" : "\033[0;30m",
"underline": "\033[4;30m",
"background": "\033[40m",
"bold":"\033[1;30m",
"hi_text":"\033[0;90m",
"hi_bold" : "\033[1;90m",
"hi_background" : "\033[0;100m"
},
"RED" : {
"text" : "\033[0;31m",
"bold":"\033[1;31m",
"underline": "\033[4;31m",
"background": "\033[41m",
"hi_text":"\033[0;91m",
"hi_bold" : "\033[1;91m",
"hi_background" : "\033[0;101m"
},
"GREEN" : {
"text" : "\033[0;32m",
"bold":"\033[1;32m",
"underline": "\033[4;32m",
"background": "\033[42m",
"hi_text":"\033[0;92m",
"hi_bold" : "\033[1;92m",
"hi_background" : "\033[0;102m"
},
"YELLOW" : {
"text" : "\033[0;33m",
"bold":"\033[1;33m",
"underline": "\033[4;33m",
"background": "\033[43m",
"hi_text":"\033[0;93m",
"hi_bold" : "\033[1;93m",
"hi_background" : "\033[0;103m"
},
"BLUE" : {
"text" : "\033[0;34m",
"bold":"\033[1;34m",
"underline": "\033[4;34m",
"background": "\033[44m",
"hi_text":"\033[0;94m",
"hi_bold" : "\033[1;94m",
"hi_background" : "\033[0;104m"
},
"PURPLE" : {
"text" : "\033[0;35m",
"bold":"\033[1;35m",
"underline": "\033[4;35m",
"background": "\033[45m",
"hi_text":"\033[0;95m",
"hi_bold" : "\033[1;95m",
"hi_background" : "\033[0;105m"
},
"CYAN" : {
"text" : "\033[0;36m",
"bold":"\033[1;36m",
"underline": "\033[4;36m",
"background": "\033[46m",
"hi_text":"\033[0;96m",
"hi_bold" : "\033[1;96m",
"hi_background" : "\033[0;106m"
},
"WHITE" : {
"text" : "\033[0;37m",
"bold":"\033[1;37m",
"underline": "\033[4;37m",
"background": "\033[47m",
"hi_text":"\033[0;97m",
"hi_bold" : "\033[1;97m",
"hi_background" : "\033[0;107m"
}
};
exports.colors = {
BLACK: "BLACK",
RED: "RED",
GREEN: "GREEN",
YELLOW: "YELLOW",
BLUE: "BLUE",
PURPLE: "PURPLE",
CYAN: "CYAN",
WHITE: "WHITE"
};
var styles = exports.styles = {
bold: "bold",
underline: "underline",
background: "background",
hi_text: "hi_text",
hi_bold: "hi_bold",
hi_background: "hi_background"
};
var REMOVE_COLOR = exports.REMOVE_COLOR = "\033[0m";
// various logical inconsistencies in the code below - renderColor and wrap seem like they should be combined, but I'm letting wrap basically stand on its own
// in case anyone wants access to explicitly handle background or underline stuff. I feel like those are a bit more special-casey, and generally speakign
// users are going to want to quickly turn a word or phrase into a single color without worrying about background or underline. So the .colorName methods
// are just syntactic sugar.
exports.wrap = function(str, color, style) {
var c = bash_codes[color.toUpperCase()];
var s = styles[style] || "text";
return render(c[s], str);
};
exports.black = function(str, hi) {
return renderColor(str, bash_codes.BLACK, hi);
};
exports.red = function(str, hi) {
return renderColor(str, bash_codes.RED, hi);
};
exports.green = function(str, hi) {
return renderColor(str, bash_codes.GREEN, hi);
};
exports.yellow = function(str, hi) {
return renderColor(str, bash_codes.YELLOW, hi);
};
exports.blue = function(str, hi) {
return renderColor(str, bash_codes.BLUE, hi);
};
exports.purple = function(str, hi) {
return renderColor(str, bash_codes.PURPLE, hi);
};
exports.cyan = function(str, hi) {
return renderColor(str, bash_codes.CYAN, hi);
};
exports.white = function(str, hi) {
return renderColor(str, bash_codes.WHITE, hi);
};
function renderColor(str, color, hi) {
return render(hi ? color.hi_text : color.text, str);
}
function render(code, str) {
return code + str + REMOVE_COLOR;
}
|