Add extended pipe color codes (24-31) ala Mystic et. al.

This commit is contained in:
Bryan Ashby 2017-11-18 16:15:50 -07:00
parent 02cd8c26c7
commit 617f0ef07e
1 changed files with 42 additions and 58 deletions

View File

@ -87,33 +87,8 @@ function enigmaStrLen(s) {
return stripEnigmaCodes(s).length; return stripEnigmaCodes(s).length;
} }
function renegadeToAnsi(s, client) { function ansiSgrFromRenegadeColorCode(cc) {
if(-1 == s.indexOf('|')) { return ansi.sgr({
return s; // no pipe codes present
}
var result = '';
var re = /\|([A-Z\d]{2}|\|)/g;
var m;
var lastIndex = 0;
while((m = re.exec(s))) {
var val = m[1];
if('|' == val) {
result += '|';
continue;
}
// convert to number
val = parseInt(val, 10);
if(isNaN(val)) {
val = getPredefinedMCIValue(client, m[1]) || ('|' + m[1]); // value itself or literal
}
if(_.isString(val)) {
result += s.substr(lastIndex, m.index - lastIndex) + val;
} else {
var attr = ansi.sgr({
0 : [ 'reset', 'black' ], 0 : [ 'reset', 'black' ],
1 : [ 'reset', 'blue' ], 1 : [ 'reset', 'blue' ],
2 : [ 'reset', 'green' ], 2 : [ 'reset', 'green' ],
@ -140,8 +115,45 @@ function renegadeToAnsi(s, client) {
21 : [ 'magentaBG' ], 21 : [ 'magentaBG' ],
22 : [ 'yellowBG' ], 22 : [ 'yellowBG' ],
23 : [ 'whiteBG' ], 23 : [ 'whiteBG' ],
}[val] || 'normal');
24 : [ 'bold', 'blackBG' ],
25 : [ 'bold', 'blueBG' ],
26 : [ 'bold', 'greenBG' ],
27 : [ 'bold', 'cyanBG' ],
28 : [ 'bold', 'redBG' ],
29 : [ 'bold', 'magentaBG' ],
30 : [ 'bold', 'yellowBG' ],
31 : [ 'bold', 'whiteBG' ],
}[cc] || 'normal');
}
function renegadeToAnsi(s, client) {
if(-1 == s.indexOf('|')) {
return s; // no pipe codes present
}
var result = '';
var re = /\|([A-Z\d]{2}|\|)/g;
var m;
var lastIndex = 0;
while((m = re.exec(s))) {
var val = m[1];
if('|' == val) {
result += '|';
continue;
}
// convert to number
val = parseInt(val, 10);
if(isNaN(val)) {
val = getPredefinedMCIValue(client, m[1]) || ('|' + m[1]); // value itself or literal
}
if(_.isString(val)) {
result += s.substr(lastIndex, m.index - lastIndex) + val;
} else {
const attr = ansiSgrFromRenegadeColorCode(val);
result += s.substr(lastIndex, m.index - lastIndex) + attr; result += s.substr(lastIndex, m.index - lastIndex) + attr;
} }
@ -190,35 +202,7 @@ function controlCodesToAnsi(s, client) {
if(_.isString(v)) { if(_.isString(v)) {
result += s.substr(lastIndex, m.index - lastIndex) + v; result += s.substr(lastIndex, m.index - lastIndex) + v;
} else { } else {
v = ansi.sgr({ v = ansiSgrFromRenegadeColorCode(v);
0 : [ 'reset', 'black' ],
1 : [ 'reset', 'blue' ],
2 : [ 'reset', 'green' ],
3 : [ 'reset', 'cyan' ],
4 : [ 'reset', 'red' ],
5 : [ 'reset', 'magenta' ],
6 : [ 'reset', 'yellow' ],
7 : [ 'reset', 'white' ],
8 : [ 'bold', 'black' ],
9 : [ 'bold', 'blue' ],
10 : [ 'bold', 'green' ],
11 : [ 'bold', 'cyan' ],
12 : [ 'bold', 'red' ],
13 : [ 'bold', 'magenta' ],
14 : [ 'bold', 'yellow' ],
15 : [ 'bold', 'white' ],
16 : [ 'blackBG' ],
17 : [ 'blueBG' ],
18 : [ 'greenBG' ],
19 : [ 'cyanBG' ],
20 : [ 'redBG' ],
21 : [ 'magentaBG' ],
22 : [ 'yellowBG' ],
23 : [ 'whiteBG' ],
}[v] || 'normal');
result += s.substr(lastIndex, m.index - lastIndex) + v; result += s.substr(lastIndex, m.index - lastIndex) + v;
} }
break; break;