* 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.row = 1;
this.flags = 0x00;
this.style = 0x00;
//this.style = { 0 : true };
this.scrollBack = 0;
options = miscUtil.valueWithDefault(options, {
@ -75,7 +76,9 @@ function ANSIEscapeParser(options) {
//self.bgColor = 0;
self.fgColor = 39;
self.bgColor = 49;
self.flags = 0;
//self.style = { 0 : true };
//delete self.style;
self.style = 0;
};
self.rowUpdated = function() {
@ -124,7 +127,7 @@ function ANSIEscapeParser(options) {
function getProcessedMCI(mci) {
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);
} else {
return mci;
@ -164,7 +167,7 @@ function ANSIEscapeParser(options) {
self.lastMciCode = fullMciCode;
self.eraseColor = {
flags : self.flags,
flags : self.style,
fgColor : self.fgColor,
bgColor : self.bgColor,
};
@ -174,7 +177,7 @@ function ANSIEscapeParser(options) {
self.emit('mci', mciCode, id, args);
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));
} else {
literal(match[0]);
@ -278,33 +281,46 @@ function ANSIEscapeParser(options) {
// set graphic rendition
case 'm' :
// :TODO: reset state here for new system
for(i = 0, len = args.length; i < len; ++i) {
arg = args[i];
/*if(0x00 === arg) {
self.flags = 0x00;
self.resetColor();
} else {
switch(Math.floor(arg / 10)) {
case 0 : self.flags |= arg; break;
case 3 : self.fgColor = arg; break;
case 4 : self.bgColor = arg; break;
//case 3 : self.fgColor = arg - 30; break;
//case 4 : self.bgColor = arg - 40; break;
}
// :TODO: finish this system
// * style is map of styleName -> boolean
// * Change all fg/bg/etc -> self.state.color { fg, bg, style{} }
// * Change all refs to use this new system
// * When passing color -> sgr, iterate enabled styles -> additional params
// * view.getANSIColor() will need updated
// * art.js will need updated
/*
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) {
self.fgColor = arg;
} else if(arg >= 40 && arg <= 47) {
self.bgColor = arg;
} else {
self.flags |= arg;
self.style |= arg;
if(0 === arg) {
self.resetColor();
//self.flags = 0;
//self.style = 0;
}
}
}
break;
@ -321,4 +337,42 @@ function ANSIEscapeParser(options) {
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]];
}
} else if(typeof args[i] === 'number') {
} else if(typeof args[i] === 'number') {
if(result.length > 0) {
result += ';';
}

View File

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

View File

@ -179,9 +179,15 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
break;
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);
break;

View File

@ -46,7 +46,11 @@ ToggleMenuView.prototype.redraw = function() {
item.text, i === this.focusedItemIndex && this.hasFocus ? this.focusTextStyle : this.textStyle);
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()));

View File

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

View File

@ -183,6 +183,20 @@ function ViewController(options) {
setViewProp('focusTextStyle');
setViewProp('maxLength');
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) {
if(_.isNumber(v)) {

Binary file not shown.

View File

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