+ MCI support for focusArgs, e.g. 'focusTextStyle'

+ TextView initial support for fillChar and justify
+ Add color support to string_util.js::pad()
* Better color handling in Views
This commit is contained in:
Bryan Ashby 2014-11-03 16:49:15 -07:00
parent 4234e03008
commit 6c841105ab
13 changed files with 126 additions and 162 deletions

View file

@ -20,7 +20,7 @@ function TextView(client, options) {
this.multiLine = this.options.multiLine || false;
this.fillChar = miscUtil.valueWithDefault(this.options.fillChar, ' ').substr(0, 1);
this.justify = this.options.justify || 'none';
this.justify = this.options.justify || 'right';
assert(!this.multiLine); // :TODO: not yet supported
@ -40,15 +40,25 @@ util.inherits(TextView, View);
TextView.prototype.redraw = function() {
TextView.super_.prototype.redraw.call(this);
var color = this.hasFocus ? this.getFocusColor() : this.getColor();
this.client.term.write(this.getANSIColor(color));
var ansiColor = this.getANSIColor(this.hasFocus ? this.getFocusColor() : this.getColor());
// :TODO: If using fillChar, don't just pad. switch to non-focus color & fill with |fillChar|
// :TODO: Apply justification
if(this.isPasswordTextStyle) {
this.client.term.write(strUtil.pad(new Array(this.text.length + 1).join(this.textMaskChar), this.dimens.width));
this.client.term.write(strUtil.pad(
new Array(this.text.length + 1).join(this.textMaskChar),
this.dimens.width,
this.fillChar,
this.justify,
ansiColor,
this.getANSIColor(this.getColor())));
} else {
this.client.term.write(strUtil.pad(this.text, this.dimens.width));
var text = strUtil.stylizeString(this.text, this.hasFocus ? this.focusTextStyle : this.textStyle);
this.client.term.write(strUtil.pad(
text,
this.dimens.width,
this.fillChar,
this.justify,
ansiColor,
this.getANSIColor(this.getColor())));
}
};
@ -57,6 +67,7 @@ TextView.prototype.setFocus = function(focused) {
this.redraw();
this.client.term.write(ansi.goto(this.position.x, this.position.y + this.text.length));
this.client.term.write(this.getANSIColor(this.getFocusColor()));
};
TextView.prototype.setText = function(text) {
@ -66,7 +77,7 @@ TextView.prototype.setText = function(text) {
this.text = this.text.substr(0, this.maxLength);
}
this.text = strUtil.stylizeString(this.text, this.textStyle);
this.text = strUtil.stylizeString(this.text, this.hasFocus ? this.focusTextStyle : this.textStyle);
if(!this.multiLine && !this.dimens.width) {
this.dimens.width = this.text.length;