* Fixed double extra view redraws

* Redraw views when all of them are ready @ MCI init
* Moved a lot of properties of views to menu.json/prompts
* Allow scrolling editor for EditTextView
* New @config:path.to.property for menu.json view properties/etc.
This commit is contained in:
Bryan Ashby 2015-04-26 20:46:16 -06:00
parent 5288643189
commit 7a643150e7
10 changed files with 233 additions and 71 deletions

View file

@ -5,8 +5,10 @@ var View = require('./view.js').View;
var miscUtil = require('./misc_util.js');
var strUtil = require('./string_util.js');
var ansi = require('./ansi_term.js');
var util = require('util');
var assert = require('assert');
var _ = require('lodash');
exports.TextView = TextView;
@ -17,27 +19,52 @@ function TextView(options) {
if(options.maxLength) {
this.maxLength = options.maxLength;
} else {
this.maxLength = this.client.term.termWidth - this.position.x;
}
this.multiLine = options.multiLine || false;
this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1);
this.justify = options.justify || 'right';
this.resizable = miscUtil.valueWithDefault(options.resizable, true);
//this.inputType = options.inputType || 'normal';
this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1);
this.justify = options.justify || 'right';
this.resizable = miscUtil.valueWithDefault(options.resizable, true);
this.horizScroll = miscUtil.valueWithDefault(options.horizScroll, true);
this.isPasswordTextStyle = 'P' === this.textStyle || 'password' === this.textStyle;
assert(!this.multiLine); // :TODO: not yet supported
if(!this.multiLine) {
this.dimens.height = 1;
if(_.isString(options.textMaskChar) && 1 === options.textMaskChar.length) {
this.textMaskChar = options.textMaskChar;
}
this.dimens.height = 1;
this.drawText = function(s) {
var ansiColor = this.getANSIColor(this.hasFocus ? this.getFocusColor() : this.getColor());
if(this.isPasswordTextStyle) {
//
// ABCDEFGHIJK
// |ABCDEFG| ^_ length
// ^-- dimens.width
//
var textToDraw = _.isString(this.textMaskChar) ?
new Array(s.length + 1).join(this.textMaskChar) :
strUtil.stylizeString(s, this.hasFocus ? this.focusTextStyle : this.textStyle);
if(textToDraw.length > this.dimens.width) {
// XXXXXXXXXXXXXXXXX
// this is the text but too long
// text but too long
if(this.horizScroll) {
textToDraw = textToDraw.substr(textToDraw.length - this.dimens.width, textToDraw.length);//0, this.dimens.width);//textToDraw.length - (this.dimens.width + 1));
}
}
var textAnsiColor = this.getANSIColor(this.hasFocus ? this.getFocusColor() : this.getColor());
var fillAnsiColor = this.getANSIColor(this.getColor());
//console.log(textToDraw)
///console.log(this.dimens.width + 1)
this.client.term.write(strUtil.pad(textToDraw, this.dimens.width + 1, this.fillChar, this.justify, textAnsiColor, fillAnsiColor));
/*
if(_.isString(this.textMaskChar)) {
this.client.term.write(strUtil.pad(
new Array(s.length + 1).join(this.textMaskChar),
this.dimens.width + 1,
@ -55,13 +82,10 @@ function TextView(options) {
ansiColor,
this.getANSIColor(this.getColor())));
}
*/
};
this.setText(options.text || '');
if(this.isPasswordTextStyle) {
this.textMaskChar = miscUtil.valueWithDefault(options.textMaskChar, '*').substr(0, 1);
}
}
util.inherits(TextView, View);
@ -99,14 +123,8 @@ TextView.prototype.setText = function(text) {
this.text = strUtil.stylizeString(this.text, this.hasFocus ? this.focusTextStyle : this.textStyle);
/*if(!this.multiLine && !this.dimens.width) {
this.dimens.width = this.text.length;
}*/
if(!this.multiLine) {
if(this.resizable) {
this.dimens.width = this.text.length + widthDelta;
}
if(this.resizable) {
this.dimens.width = this.text.length + widthDelta;
}
this.redraw();