* Start work on new ANSI parser color/style system. Mostly notes. Will do in bulk later

* Start of styleColorX concept
This commit is contained in:
Bryan Ashby 2015-04-28 22:42:22 -06:00
parent 39fff7826c
commit 48be2f69be
9 changed files with 109 additions and 26 deletions

View File

@ -16,7 +16,8 @@ function ANSIEscapeParser(options) {
this.column = 1; this.column = 1;
this.row = 1; this.row = 1;
this.flags = 0x00; this.style = 0x00;
//this.style = { 0 : true };
this.scrollBack = 0; this.scrollBack = 0;
options = miscUtil.valueWithDefault(options, { options = miscUtil.valueWithDefault(options, {
@ -75,7 +76,9 @@ function ANSIEscapeParser(options) {
//self.bgColor = 0; //self.bgColor = 0;
self.fgColor = 39; self.fgColor = 39;
self.bgColor = 49; self.bgColor = 49;
self.flags = 0; //self.style = { 0 : true };
//delete self.style;
self.style = 0;
}; };
self.rowUpdated = function() { self.rowUpdated = function() {
@ -124,7 +127,7 @@ function ANSIEscapeParser(options) {
function getProcessedMCI(mci) { function getProcessedMCI(mci) {
if(self.mciReplaceChar.length > 0) { if(self.mciReplaceChar.length > 0) {
var eraseColor = ansi.sgr(self.eraseColor.flags, self.eraseColor.fgColor, self.eraseColor.bgColor); var eraseColor = ansi.sgr(self.eraseColor.style, self.eraseColor.fgColor, self.eraseColor.bgColor);
return eraseColor + new Array(mci.length + 1).join(self.mciReplaceChar); return eraseColor + new Array(mci.length + 1).join(self.mciReplaceChar);
} else { } else {
return mci; return mci;
@ -164,7 +167,7 @@ function ANSIEscapeParser(options) {
self.lastMciCode = fullMciCode; self.lastMciCode = fullMciCode;
self.eraseColor = { self.eraseColor = {
flags : self.flags, flags : self.style,
fgColor : self.fgColor, fgColor : self.fgColor,
bgColor : self.bgColor, bgColor : self.bgColor,
}; };
@ -174,7 +177,7 @@ function ANSIEscapeParser(options) {
self.emit('mci', mciCode, id, args); self.emit('mci', mciCode, id, args);
if(self.mciReplaceChar.length > 0) { if(self.mciReplaceChar.length > 0) {
self.emit('chunk', ansi.sgr(self.eraseColor.flags, self.eraseColor.fgColor, self.eraseColor.bgColor)); self.emit('chunk', ansi.sgr(self.eraseColor.style, self.eraseColor.fgColor, self.eraseColor.bgColor));
literal(new Array(match[0].length + 1).join(self.mciReplaceChar)); literal(new Array(match[0].length + 1).join(self.mciReplaceChar));
} else { } else {
literal(match[0]); literal(match[0]);
@ -278,33 +281,46 @@ function ANSIEscapeParser(options) {
// set graphic rendition // set graphic rendition
case 'm' : case 'm' :
// :TODO: reset state here for new system
for(i = 0, len = args.length; i < len; ++i) { for(i = 0, len = args.length; i < len; ++i) {
arg = args[i]; arg = args[i];
/*if(0x00 === arg) {
self.flags = 0x00; // :TODO: finish this system
self.resetColor(); // * style is map of styleName -> boolean
} else { // * Change all fg/bg/etc -> self.state.color { fg, bg, style{} }
switch(Math.floor(arg / 10)) { // * Change all refs to use this new system
case 0 : self.flags |= arg; break; // * When passing color -> sgr, iterate enabled styles -> additional params
case 3 : self.fgColor = arg; break; // * view.getANSIColor() will need updated
case 4 : self.bgColor = arg; break; // * art.js will need updated
//case 3 : self.fgColor = arg - 30; break; /*
//case 4 : self.bgColor = arg - 40; break; if(ANSIEscapeParser.foregroundColors[arg]) {
} self.fgColor = arg;//ANSIEscapeParser.foregroundColors[arg];
} else if(ANSIEscapeParser.backgroundColors[arg]) {
self.bgColor = arg;//ANSIEscapeParser.backgroundColors[arg];
} else if(39 === arg) {
delete self.fgColor;
} else if(49 === arg) {
delete self.bgColor;
} else if(ANSIEscapeParser.styles[arg]) {
self.style = arg;
} }
*/ */
if(arg >= 30 && arg <= 37) { if(arg >= 30 && arg <= 37) {
self.fgColor = arg; self.fgColor = arg;
} else if(arg >= 40 && arg <= 47) { } else if(arg >= 40 && arg <= 47) {
self.bgColor = arg; self.bgColor = arg;
} else { } else {
self.flags |= arg; self.style |= arg;
if(0 === arg) { if(0 === arg) {
self.resetColor(); self.resetColor();
//self.flags = 0; //self.style = 0;
} }
} }
} }
break; break;
@ -321,4 +337,42 @@ function ANSIEscapeParser(options) {
this.resetColor(); this.resetColor();
} }
util.inherits(ANSIEscapeParser, events.EventEmitter); util.inherits(ANSIEscapeParser, events.EventEmitter);
ANSIEscapeParser.foregroundColors = {
30 : 'black',
31 : 'red',
32 : 'green',
33 : 'yellow',
34 : 'blue',
35 : 'magenta',
36 : 'cyan',
37 : 'white',
90 : 'grey'
};
Object.freeze(ANSIEscapeParser.foregroundColors);
ANSIEscapeParser.backgroundColors = {
40 : 'black',
41 : 'red',
42 : 'green',
43 : 'yellow',
44 : 'blue',
45 : 'magenta',
46 : 'cyan',
47 : 'white'
};
Object.freeze(ANSIEscapeParser.backgroundColors);
ANSIEscapeParser.styles = {
0 : 'default',
1 : 'bright',
2 : 'dim',
5 : 'slow blink',
6 : 'fast blink',
7 : 'negative',
8 : 'concealed',
22 : 'normal',
27 : 'positive',
};
Object.freeze(ANSIEscapeParser.styles);

View File

@ -313,7 +313,7 @@ function sgr() {
} }
result += SGRValues[args[i]]; result += SGRValues[args[i]];
} }
} else if(typeof args[i] === 'number') { } else if(typeof args[i] === 'number') {
if(result.length > 0) { if(result.length > 0) {
result += ';'; result += ';';
} }

View File

@ -459,7 +459,7 @@ function display(options, cb) {
mci[mapItem].focusColor = { mci[mapItem].focusColor = {
fg : parser.fgColor, fg : parser.fgColor,
bg : parser.bgColor, bg : parser.bgColor,
flags : parser.flags, flags : parser.style,
}; };
mci[mapItem].focusArgs = args; mci[mapItem].focusArgs = args;
} else { } else {
@ -468,7 +468,7 @@ function display(options, cb) {
color : { color : {
fg : parser.fgColor, fg : parser.fgColor,
bg : parser.bgColor, bg : parser.bgColor,
flags : parser.flags, flags : parser.style,
}, },
code : mciCode, code : mciCode,
id : parseInt(id, 10), id : parseInt(id, 10),

View File

@ -179,9 +179,15 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
break; break;
case 'TM' : case 'TM' :
setOption(0, 'textStyle'); if(mci.args.length > 0) {
var color = { fg : parseInt(mci.args[0], 10), flags : 0 };
if(mci.args.length > 1) {
color.bg = parseInt(mci.args[1], 10);
}
options.styleColor1 = color;
}
setFocusOption(0, 'focusTextStyle') setFocusOption(0, 'focusTextStyle');
view = new ToggleMenuView(options); view = new ToggleMenuView(options);
break; break;

View File

@ -46,7 +46,11 @@ ToggleMenuView.prototype.redraw = function() {
item.text, i === this.focusedItemIndex && this.hasFocus ? this.focusTextStyle : this.textStyle); item.text, i === this.focusedItemIndex && this.hasFocus ? this.focusTextStyle : this.textStyle);
if(1 === i) { if(1 === i) {
this.client.term.write(this.getANSIColor(this.getColor()) + ' / '); // :TODO: We need a color for this!!! //console.log(this.styleColor1)
var sepColor = this.getANSIColor(this.styleColor1 || this.getColor());
console.log(sepColor.substr(1))
//sepColor = '\u001b[0m\u001b[1;30m';
this.client.term.write(sepColor + ' / ');
} }
this.client.term.write(this.getANSIColor(i === this.focusedItemIndex ? this.getFocusColor() : this.getColor())); this.client.term.write(this.getANSIColor(i === this.focusedItemIndex ? this.getFocusColor() : this.getColor()));

View File

@ -67,6 +67,10 @@ function View(options) {
this.color = options.color || { flags : 0, fg : 7, bg : 0 }; this.color = options.color || { flags : 0, fg : 7, bg : 0 };
this.focusColor = options.focusColor || this.color; this.focusColor = options.focusColor || this.color;
if(options.styleColor1) {
this.styleColor1 = options.styleColor1;
}
if(this.acceptsInput) { if(this.acceptsInput) {
this.specialKeyMap = options.specialKeyMap || VIEW_SPECIAL_KEY_MAP_DEFAULT; this.specialKeyMap = options.specialKeyMap || VIEW_SPECIAL_KEY_MAP_DEFAULT;
} }

View File

@ -183,6 +183,20 @@ function ViewController(options) {
setViewProp('focusTextStyle'); setViewProp('focusTextStyle');
setViewProp('maxLength'); setViewProp('maxLength');
setViewProp('width', function(v) { view.dimens.width = parseInt(v, 10); }); setViewProp('width', function(v) { view.dimens.width = parseInt(v, 10); });
setViewProp('styleColor1', function(v) {
if(!_.has(v, 'fg')) {
return;
}
var color = {
fg : v.fg,
bg : v.bg || 0,
flags : v.flags || 0
};
view.styleColor1 = color;
});
setViewProp('fillChar', function(v) { setViewProp('fillChar', function(v) {
if(_.isNumber(v)) { if(_.isNumber(v)) {

Binary file not shown.

View File

@ -266,7 +266,8 @@
"items" : [ "Razor 1911", "DrinkOrDie", "TRSI" ] "items" : [ "Razor 1911", "DrinkOrDie", "TRSI" ]
}, },
"TM3" : { "TM3" : {
"items" : [ "Yarly", "Nowaii" ] "items" : [ "Yarly", "Nowaii" ],
"styleColor1" : { "fg" : 30, "flags" : 1 }
}, },
"BT8" : { "BT8" : {
"text" : "< Back", "text" : "< Back",