* A bit of work on VerticalMenuView
* Inheritance updates for Views * Fixes and better handling of MCI factory
This commit is contained in:
parent
c3aa4c44e2
commit
edc8266310
|
@ -163,8 +163,6 @@ function ANSIEscapeParser(options) {
|
||||||
|
|
||||||
|
|
||||||
self.emit('mci', mciCode, id, args);
|
self.emit('mci', mciCode, id, args);
|
||||||
console.log(self.row + ', ' + self.column);
|
|
||||||
console.log(match[0]);
|
|
||||||
|
|
||||||
if(self.mciReplaceChar.length > 0) {
|
if(self.mciReplaceChar.length > 0) {
|
||||||
escape('m', [self.lastFlags, self.lastFgColor, self.lastBgColor]);
|
escape('m', [self.lastFlags, self.lastFgColor, self.lastBgColor]);
|
||||||
|
|
|
@ -426,6 +426,7 @@ function display(art, options, cb) {
|
||||||
parser.on('mci', function onMCI(mciCode, id, args) {
|
parser.on('mci', function onMCI(mciCode, id, args) {
|
||||||
id = id || generatedId++;
|
id = id || generatedId++;
|
||||||
var mapItem = mciCode + id;
|
var mapItem = mciCode + id;
|
||||||
|
// :TODO: Avoid mutiple [] lookups here
|
||||||
if(mci[mapItem]) {
|
if(mci[mapItem]) {
|
||||||
mci[mapItem].focusColor = {
|
mci[mapItem].focusColor = {
|
||||||
fg : parser.fgColor,
|
fg : parser.fgColor,
|
||||||
|
|
|
@ -6,9 +6,6 @@ var paths = require('path');
|
||||||
var miscUtil = require('./misc_util.js');
|
var miscUtil = require('./misc_util.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// :TODO: remove this ... anti-pattern!
|
|
||||||
//config : undefined,
|
|
||||||
|
|
||||||
defaultPath : function() {
|
defaultPath : function() {
|
||||||
var base = miscUtil.resolvePath('~/');
|
var base = miscUtil.resolvePath('~/');
|
||||||
if(base) {
|
if(base) {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
/* jslint node: true */
|
/* jslint node: true */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var TextView = require('./text_view.js').TextView;
|
var TextView = require('./text_view.js').TextView;
|
||||||
var EditTextView = require('./edit_text_view.js').EditTextView;
|
var EditTextView = require('./edit_text_view.js').EditTextView;
|
||||||
var ButtonView = require('./button_view.js').ButtonView;
|
var ButtonView = require('./button_view.js').ButtonView;
|
||||||
var Config = require('./config.js').config;
|
var VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
||||||
var packageJson = require('../package.json');
|
var Config = require('./config.js').config;
|
||||||
var assert = require('assert');
|
var packageJson = require('../package.json');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
exports.MCIViewFactory = MCIViewFactory;
|
exports.MCIViewFactory = MCIViewFactory;
|
||||||
|
|
||||||
|
@ -19,11 +20,19 @@ MCIViewFactory.prototype.getPredefinedViewLabel = function(name) {
|
||||||
switch(name) {
|
switch(name) {
|
||||||
case 'BN' : label = Config.bbsName; break;
|
case 'BN' : label = Config.bbsName; break;
|
||||||
case 'VL' : label = 'ENiGMA½ v' + packageJson.version; break;
|
case 'VL' : label = 'ENiGMA½ v' + packageJson.version; break;
|
||||||
|
case 'VN' : label = packageJson.version; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return label;
|
return label;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// :TODO: probably do something like this and generalize all of this:
|
||||||
|
/*
|
||||||
|
var MCI_ARG_MAP = {
|
||||||
|
'ET' : { 0 : 'maxLength', 1 : 'textStyle' }
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
MCIViewFactory.prototype.createFromMCI = function(mci) {
|
MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||||
assert(mci.code);
|
assert(mci.code);
|
||||||
assert(mci.id > 0);
|
assert(mci.id > 0);
|
||||||
|
@ -37,8 +46,18 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||||
position : { x : mci.position[0], y : mci.position[1] },
|
position : { x : mci.position[0], y : mci.position[1] },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// :TODO: move this stuff out of the switch to their own methods/objects
|
||||||
|
function setOption(pos, name) {
|
||||||
|
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
||||||
|
options[name] = mci.args[pos];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch(mci.code) {
|
switch(mci.code) {
|
||||||
case 'TL' :
|
case 'TL' :
|
||||||
|
// :TODO: convert to setOption()
|
||||||
if(mci.args.length > 0) {
|
if(mci.args.length > 0) {
|
||||||
options.textStyle = mci.args[0];
|
options.textStyle = mci.args[0];
|
||||||
}
|
}
|
||||||
|
@ -56,19 +75,17 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ET' :
|
case 'ET' :
|
||||||
if(mci.args.length > 0) {
|
if(setOption(0, 'maxLength')) {
|
||||||
options.maxLength = mci.args[0];
|
options.dimens = { width : options.maxLength };
|
||||||
options.dimens = { width : options.maxLength };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mci.args.length > 1) {
|
setOption(1, 'textStyle');
|
||||||
options.textStyle = mci.args[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
view = new EditTextView(this.client, options);
|
view = new EditTextView(this.client, options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'PL' :
|
case 'PL' :
|
||||||
|
// :TODO: convert to setOption()
|
||||||
if(mci.args.length > 0) {
|
if(mci.args.length > 0) {
|
||||||
options.text = this.getPredefinedViewLabel(mci.args[0]);
|
options.text = this.getPredefinedViewLabel(mci.args[0]);
|
||||||
if(options.text) {
|
if(options.text) {
|
||||||
|
@ -91,6 +108,7 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'BV' :
|
case 'BV' :
|
||||||
|
// :TODO: convert to setOption()
|
||||||
if(mci.args.length > 0) {
|
if(mci.args.length > 0) {
|
||||||
options.text = mci.args[0];
|
options.text = mci.args[0];
|
||||||
options.dimens = { width : options.text.length };
|
options.dimens = { width : options.text.length };
|
||||||
|
@ -98,6 +116,12 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||||
|
|
||||||
view = new ButtonView(this.client, options);
|
view = new ButtonView(this.client, options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'VM' :
|
||||||
|
setOption(0, 'itemSpacing');
|
||||||
|
|
||||||
|
view = new VerticalMenuView(this.client, options);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|
|
@ -3,26 +3,39 @@
|
||||||
|
|
||||||
var View = require('./view.js').View;
|
var View = require('./view.js').View;
|
||||||
var ansi = require('./ansi_term.js');
|
var ansi = require('./ansi_term.js');
|
||||||
|
var miscUtil = require('./misc_util.js');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
exports.MenuView = MenuView;
|
exports.MenuView = MenuView;
|
||||||
|
|
||||||
function MenuView(client, options) {
|
function MenuView(client, options) {
|
||||||
|
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
|
||||||
|
var self = this;
|
||||||
|
|
||||||
View.call(this, client, options);
|
View.call(this, client, options);
|
||||||
|
|
||||||
|
this.focusedItemIndex = 0;
|
||||||
|
|
||||||
|
|
||||||
|
//// --- TESTING
|
||||||
|
options.items = [ 'Login', 'Apply', 'Logout' ];
|
||||||
|
//options.itemSpacing = 2;
|
||||||
|
//// --- TESTING
|
||||||
|
|
||||||
this.items = [];
|
this.items = [];
|
||||||
if(this.options.items) {
|
if(this.options.items) {
|
||||||
this.options.items.forEach(function onItem(itemText) {
|
this.options.items.forEach(function onItem(itemText) {
|
||||||
this.items.push({
|
self.items.push({
|
||||||
text : itemText,
|
text : itemText,
|
||||||
focused : false,
|
|
||||||
selected : false,
|
selected : false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.itemSpacing = this.options.itemSpacing || 1;
|
this.itemSpacing = this.options.itemSpacing || 1;
|
||||||
|
this.itemSpacing = parseInt(this.itemSpacing, 10);
|
||||||
|
|
||||||
this.focusPrefix = this.options.focusPrefix || '';
|
this.focusPrefix = this.options.focusPrefix || '';
|
||||||
this.focusSuffix = this.options.focusSuffix || '';
|
this.focusSuffix = this.options.focusSuffix || '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ function TextView(client, options) {
|
||||||
this.maxLength = this.options.maxLength;
|
this.maxLength = this.options.maxLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.textStyle = this.options.textStyle || 'normal';
|
|
||||||
this.multiLine = this.options.multiLine || false;
|
this.multiLine = this.options.multiLine || false;
|
||||||
this.fillChar = miscUtil.valueWithDefault(this.options.fillChar, ' ').substr(0, 1);
|
this.fillChar = miscUtil.valueWithDefault(this.options.fillChar, ' ').substr(0, 1);
|
||||||
|
|
||||||
|
@ -29,8 +28,6 @@ function TextView(client, options) {
|
||||||
|
|
||||||
this.setText(this.options.text || '');
|
this.setText(this.options.text || '');
|
||||||
|
|
||||||
this.isPasswordTextStyle = 'P' === this.textStyle || 'password' === this.textStyle;
|
|
||||||
|
|
||||||
if(this.isPasswordTextStyle) {
|
if(this.isPasswordTextStyle) {
|
||||||
this.textMaskChar = miscUtil.valueWithDefault(this.options.textMaskChar, '*').substr(0, 1);
|
this.textMaskChar = miscUtil.valueWithDefault(this.options.textMaskChar, '*').substr(0, 1);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +42,7 @@ TextView.prototype.redraw = function() {
|
||||||
this.client.term.write(this.getANSIColor(color));
|
this.client.term.write(this.getANSIColor(color));
|
||||||
|
|
||||||
// :TODO: If using fillChar, don't just pad. switch to non-focus color & fill with |fillChar|
|
// :TODO: If using fillChar, don't just pad. switch to non-focus color & fill with |fillChar|
|
||||||
|
// :TODO: Apply justification
|
||||||
if(this.isPasswordTextStyle) {
|
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));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,15 +3,70 @@
|
||||||
|
|
||||||
var MenuView = require('./menu_view.js').MenuView;
|
var MenuView = require('./menu_view.js').MenuView;
|
||||||
var ansi = require('./ansi_term.js');
|
var ansi = require('./ansi_term.js');
|
||||||
|
var strUtil = require('./string_util.js');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
|
exports.VerticalMenuView = VerticalMenuView;
|
||||||
|
|
||||||
function VerticalMenuView(client, options) {
|
function VerticalMenuView(client, options) {
|
||||||
MenuView.call(this, client, options);
|
MenuView.call(this, client, options);
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
this.cacheXPositions = function() {
|
||||||
|
if(self.xPositionCacheExpired) {
|
||||||
|
var count = this.items.length;
|
||||||
|
var x = self.position.x;
|
||||||
|
for(var i = 0; i < count; ++i) {
|
||||||
|
if(i > 0) {
|
||||||
|
x += self.itemSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.items[i].xPosition = x;
|
||||||
|
}
|
||||||
|
self.xPositionCacheExpired = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(VerticalMenuView, MenuView);
|
util.inherits(VerticalMenuView, MenuView);
|
||||||
|
|
||||||
|
VerticalMenuView.prototype.setPosition = function(pos) {
|
||||||
|
VerticalMenuView.super_.prototype.setPosition.call(this, pos);
|
||||||
|
|
||||||
|
this.xPositionCacheExpired = true;
|
||||||
|
};
|
||||||
|
|
||||||
VerticalMenuView.prototype.redraw = function() {
|
VerticalMenuView.prototype.redraw = function() {
|
||||||
VerticalMenuView.super_.prototype.redraw.call(this);
|
VerticalMenuView.super_.prototype.redraw.call(this);
|
||||||
|
|
||||||
|
var color = this.getColor();
|
||||||
|
var focusColor = this.getFocusColor();
|
||||||
|
console.log(focusColor);
|
||||||
|
var x = this.position.x;
|
||||||
|
var y = this.position.y;
|
||||||
|
|
||||||
|
var count = this.items.length;
|
||||||
|
var item;
|
||||||
|
var text;
|
||||||
|
|
||||||
|
this.cacheXPositions();
|
||||||
|
|
||||||
|
for(var i = 0; i < count; ++i) {
|
||||||
|
item = this.items[i];
|
||||||
|
|
||||||
|
this.client.term.write(ansi.goto(item.xPosition, y));
|
||||||
|
|
||||||
|
this.client.term.write(this.getANSIColor(i === this.focusedItemIndex || item.selected ? focusColor : color));
|
||||||
|
|
||||||
|
text = strUtil.stylizeString(item.text, item.hasFocus ? this.focusTextStyle : this.textStyle);
|
||||||
|
this.client.term.write(text); // :TODO: apply justify, and style
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
VerticalMenuView.prototype.setFocus = function(focused) {
|
||||||
|
VerticalMenuView.super_.prototype.setFocus.call(this, focused);
|
||||||
|
|
||||||
|
this.redraw();
|
||||||
};
|
};
|
|
@ -33,6 +33,9 @@ function View(client, options) {
|
||||||
this.position = { x : 0, y : 0 };
|
this.position = { x : 0, y : 0 };
|
||||||
this.dimens = { height : 1, width : 0 };
|
this.dimens = { height : 1, width : 0 };
|
||||||
|
|
||||||
|
this.textStyle = this.options.textStyle || 'normal';
|
||||||
|
this.focusTextStyle = this.options.focusTextStyle || this.textStyle;
|
||||||
|
|
||||||
if(this.options.id) {
|
if(this.options.id) {
|
||||||
this.setId(this.options.id);
|
this.setId(this.options.id);
|
||||||
}
|
}
|
||||||
|
@ -41,6 +44,8 @@ function View(client, options) {
|
||||||
this.setPosition(this.options.position);
|
this.setPosition(this.options.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.isPasswordTextStyle = 'P' === this.textStyle || 'password' === this.textStyle;
|
||||||
|
|
||||||
// :TODO: Don't allow width/height > client.term
|
// :TODO: Don't allow width/height > client.term
|
||||||
if(this.options.dimens && this.options.dimens.height) {
|
if(this.options.dimens && this.options.dimens.height) {
|
||||||
this.dimens.height = this.options.dimens.height;
|
this.dimens.height = this.options.dimens.height;
|
||||||
|
|
|
@ -126,15 +126,17 @@ ViewController.prototype.setViewOrder = function(order) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var view;
|
if(viewIdOrder.length > 0) {
|
||||||
var count = viewIdOrder.length - 1;
|
var view;
|
||||||
for(var i = 0; i < count; ++i) {
|
var count = viewIdOrder.length - 1;
|
||||||
this.views[viewIdOrder[i]].nextId = viewIdOrder[i + 1];
|
for(var i = 0; i < count; ++i) {
|
||||||
}
|
this.views[viewIdOrder[i]].nextId = viewIdOrder[i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
this.firstId = viewIdOrder[0];
|
this.firstId = viewIdOrder[0];
|
||||||
var lastId = viewIdOrder[viewIdOrder.length - 1];
|
var lastId = viewIdOrder.length > 1 ? viewIdOrder[viewIdOrder.length - 1] : this.firstId;
|
||||||
this.views[lastId].nextId = this.firstId;
|
this.views[lastId].nextId = this.firstId;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ViewController.prototype.loadFromMCIMap = function(mciMap) {
|
ViewController.prototype.loadFromMCIMap = function(mciMap) {
|
||||||
|
@ -148,7 +150,7 @@ ViewController.prototype.loadFromMCIMap = function(mciMap) {
|
||||||
if(view) {
|
if(view) {
|
||||||
view.on('action', self.onViewAction);
|
view.on('action', self.onViewAction);
|
||||||
self.addView(view);
|
self.addView(view);
|
||||||
view.redraw();
|
view.redraw(); // :TODO: This can result in double redraw() if we set focus on this item after
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@ function entryPoint(client) {
|
||||||
|
|
||||||
//art.getArt('SO-CC1.ANS'/* 'MATRIX'*/, { types: ['.ans'], random: true}, function onArt(err, theArt) {
|
//art.getArt('SO-CC1.ANS'/* 'MATRIX'*/, { types: ['.ans'], random: true}, function onArt(err, theArt) {
|
||||||
//client.user.properties.art_theme_id = '';
|
//client.user.properties.art_theme_id = '';
|
||||||
theme.getThemeArt('MATRIX_1', client.user.properties.art_theme_id, function onArt(err, theArt) {
|
theme.getThemeArt('MCI_VM1.ANS', client.user.properties.art_theme_id, function onArt(err, theArt) {
|
||||||
|
|
||||||
//art.getArt('MATRIX_1.ANS', {}, function onArt(err, theArt) {
|
//art.getArt('MATRIX_1.ANS', {}, function onArt(err, theArt) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
|
@ -65,46 +65,6 @@ function entryPoint(client) {
|
||||||
//vc.getView(4).setText('Login');
|
//vc.getView(4).setText('Login');
|
||||||
vc.setViewOrder();
|
vc.setViewOrder();
|
||||||
vc.switchFocus(1);
|
vc.switchFocus(1);
|
||||||
//vc.addView(etv);
|
|
||||||
//vc.switchFocus(2);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
client.on('key press', function onKp(key, isSpecial) {
|
|
||||||
key = 'string' === typeof key ? key : key.toString();
|
|
||||||
etv.onKeyPress(key, isSpecial);
|
|
||||||
});
|
|
||||||
|
|
||||||
client.on('special key', function onSK(keyName) {
|
|
||||||
etv.onSpecialKeyPress(keyName);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
var vc = new view.ViewsController(client);
|
|
||||||
vc.loadFromMCIMap(mci);
|
|
||||||
vc.setViewOrder();
|
|
||||||
vc.switchFocus(1);
|
|
||||||
vc.setSubmitView(2);
|
|
||||||
|
|
||||||
vc.on('action', function onAction(act) {
|
|
||||||
if('submit' === act.action) {
|
|
||||||
var un = vc.getView(1).value;
|
|
||||||
var pw = vc.getView(2).value;
|
|
||||||
console.log('userName: ' + un);
|
|
||||||
console.log('password: ' + pw);
|
|
||||||
|
|
||||||
user.User.loadWithCredentials(un, pw, function onUser(err, user) {
|
|
||||||
if(err) {
|
|
||||||
console.log(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(user.id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue