* Start work on allowing pipe codes & custom drawing using items vs focusItems for menus. EXPERIMENTAL.

This commit is contained in:
Bryan Ashby 2015-08-25 23:17:09 -06:00
parent 64c8d83559
commit 9442760679
10 changed files with 171 additions and 20 deletions

View File

@ -7,6 +7,7 @@ var assert = require('assert');
exports.pipeToAnsi = exports.enigmaToAnsi = enigmaToAnsi; exports.pipeToAnsi = exports.enigmaToAnsi = enigmaToAnsi;
exports.stripPipeCodes = exports.stripEnigmaCodes = stripEnigmaCodes; exports.stripPipeCodes = exports.stripEnigmaCodes = stripEnigmaCodes;
exports.pipeStrLen = exports.enigmaStrLen = enigmaStrLen;
exports.renegadeToAnsi = renegadeToAnsi; exports.renegadeToAnsi = renegadeToAnsi;
// :TODO: Not really happy with the module name of "color_codes". Would like something better // :TODO: Not really happy with the module name of "color_codes". Would like something better
@ -63,6 +64,14 @@ function enigmaToAnsi(s) {
return result; return result;
} }
function stripEnigmaCodes(s) {
return s.replace(/\|[\d]{2}/g, '');
}
function enigmaStrLen(s) {
return stripEnigmaCodes(s).length;
}
function renegadeToAnsi(s) { function renegadeToAnsi(s) {
if(-1 == s.indexOf('|')) { if(-1 == s.indexOf('|')) {
return s; // no pipe codes present return s; // no pipe codes present
@ -124,8 +133,3 @@ if(-1 == s.indexOf('|')) {
return result; return result;
} }
function stripEnigmaCodes(s) {
return s.replace(/\|[\d]{2}/g, '');
}

View File

@ -23,7 +23,7 @@ function Door(client, exeInfo) {
// exeInfo.cwd // exeInfo.cwd
// exeInfo.encoding // exeInfo.encoding
}; }
require('util').inherits(Door, events.EventEmitter); require('util').inherits(Door, events.EventEmitter);

View File

@ -40,6 +40,10 @@ function MenuView(options) {
this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1); this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1);
this.justify = options.justify || 'none'; this.justify = options.justify || 'none';
this.hasFocusItems = function() {
return !_.isUndefined(self.focusItems);
};
} }
util.inherits(MenuView, View); util.inherits(MenuView, View);
@ -48,14 +52,23 @@ MenuView.prototype.setItems = function(items) {
var self = this; var self = this;
if(items) { if(items) {
this.items = []; // :TODO: better way? this.items = []; // :TODO: better way?
items.forEach(function onItem(itemText) { items.forEach(function item(itemText) {
self.items.push({ self.items.push( { text : itemText } );
text : itemText
});
}); });
} }
}; };
MenuView.prototype.setFocusItems = function(items) {
var self = this;
if(items) {
this.focusItems = [];
items.forEach(function item(itemText) {
self.focusItems.push( { text : itemText } );
});
}
}
MenuView.prototype.setItemSpacing = function(itemSpacing) { MenuView.prototype.setItemSpacing = function(itemSpacing) {
itemSpacing = parseInt(itemSpacing); itemSpacing = parseInt(itemSpacing);
assert(_.isNumber(itemSpacing)); assert(_.isNumber(itemSpacing));
@ -68,6 +81,7 @@ MenuView.prototype.setPropertyValue = function(propName, value) {
switch(propName) { switch(propName) {
case 'itemSpacing' : this.setItemSpacing(value); break; case 'itemSpacing' : this.setItemSpacing(value); break;
case 'items' : this.setItems(value); break; case 'items' : this.setItems(value); break;
case 'focusItems' : this.setFocusItems(value); break;
case 'hotKeys' : this.setHotKeys(value); break; case 'hotKeys' : this.setHotKeys(value); break;
} }

View File

@ -128,7 +128,7 @@ function logoff(callingMenu, formData, extraArgs) {
// //
client.term.write( client.term.write(
ansi.normal() + '\n' + ansi.normal() + '\n' +
require('crypto').randomBytes(Math.floor(Math.random() * 25) + 5).toString() + require('crypto').randomBytes(Math.floor(Math.random() * 35) + 10).toString(client.term.outputEncoding) +
'NO CARRIER'); 'NO CARRIER');
client.end(); client.end();

View File

@ -5,6 +5,7 @@ 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 strUtil = require('./string_util.js');
var miscUtil = require('./misc_util.js'); var miscUtil = require('./misc_util.js');
var colorCodes = require('./color_codes.js');
var util = require('util'); var util = require('util');
var assert = require('assert'); var assert = require('assert');
@ -48,6 +49,7 @@ function VerticalMenuView(options) {
}; };
}; };
/*
this.drawItem = function(index) { this.drawItem = function(index) {
var item = self.items[index]; var item = self.items[index];
if(!item) { if(!item) {
@ -61,6 +63,47 @@ function VerticalMenuView(options) {
strUtil.pad(text, this.dimens.width, this.fillChar, this.justify) strUtil.pad(text, this.dimens.width, this.fillChar, this.justify)
); );
}; };
*/
this.drawItem = function(index) {
var item = self.items[index];
if(!item) {
return;
}
var focusItem;
var text;
if(self.hasFocusItems()) {
focusItem = self.focusItems[index];
}
if(focusItem) {
if(item.focused) {
text = strUtil.stylizeString(focusItem.text, self.focusTextStyle);
} else {
text = strUtil.stylizeString(item.text, self.textStyle);
}
// :TODO: Need to support pad()
// :TODO: shoudl we detect if pipe codes are used?
self.client.term.write(
ansi.goto(item.row, self.position.col) +
colorCodes.enigmaToAnsi(text)
);
} else {
text = strUtil.stylizeString(item.text, item.focused ? self.focusTextStyle : self.textStyle);
self.client.term.write(
ansi.goto(item.row, self.position.col) +
(index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR()) +
strUtil.pad(text, this.dimens.width, this.fillChar, this.justify)
);
}
};
} }
util.inherits(VerticalMenuView, MenuView); util.inherits(VerticalMenuView, MenuView);
@ -161,6 +204,12 @@ VerticalMenuView.prototype.setItems = function(items) {
this.positionCacheExpired = true; this.positionCacheExpired = true;
}; };
VerticalMenuView.prototype.setFocusItems = function(items) {
VerticalMenuView.super_.prototype.setFocusItems.call(this, items);
this.positionCacheExpired = true;
}
VerticalMenuView.prototype.setItemSpacing = function(itemSpacing) { VerticalMenuView.prototype.setItemSpacing = function(itemSpacing) {
VerticalMenuView.super_.prototype.setItemSpacing.call(this, itemSpacing); VerticalMenuView.super_.prototype.setItemSpacing.call(this, itemSpacing);

View File

@ -153,11 +153,11 @@ function AbracadabraModule(options) {
self.client.term.write(ansi.resetScreen()); self.client.term.write(ansi.resetScreen());
doorInstance.run(); doorInstance.run();
} };
this.fallbackModule = function() { this.fallbackModule = function() {
self.client.gotoMenuModule( { name : self.menuConfig.fallback } ); self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
} };
} }
require('util').inherits(AbracadabraModule, MenuModule); require('util').inherits(AbracadabraModule, MenuModule);

Binary file not shown.

View File

@ -571,9 +571,7 @@
"Vertical Menu Views", "Vertical Menu Views",
"Horizontal Menu Views", "Horizontal Menu Views",
"Art Display", "Art Display",
"Full Screen Editor", "Full Screen Editor"
"Some More Stuff",
"Other"
], ],
"height" : 10, "height" : 10,
"itemSpacing" : 1, "itemSpacing" : 1,
@ -599,6 +597,10 @@
"value" : { "1" : 3 }, "value" : { "1" : 3 },
"action" : "@menu:demoMultiLineEditTextView" "action" : "@menu:demoMultiLineEditTextView"
}, },
{
"value" : { "1" : 4 },
"action" : "@menu:demoVerticalMenuView"
},
{ {
"value" : { "1" : 5 }, "value" : { "1" : 5 },
"action" : "@menu:demoHorizontalMenuView" "action" : "@menu:demoHorizontalMenuView"
@ -817,6 +819,53 @@
} }
} }
}, },
"demoVerticalMenuView" : {
"art" : "demo_vertical_menu_view1.ans",
"options" : { "cls" : true },
"form" : {
"0" : {
"BTVM" : {
"mci" : {
"VM1" : {
"items" : [
"|33Oblivion/2",
"|33iNiQUiTY",
"|33ViSiON/X"
],
"focusItems" : [
"|33Oblivion|01/|00|332",
"|01|33i|00|33N|01i|00|33QU|01i|00|33TY",
"|33ViSiON/X"
]
//
// :TODO: how to do the following:
// 1) Supply a view a string for a standard vs focused item
// "items" : [...], "focusItems" : [ ... ] ?
// "draw" : "@method:drawItemX", then items: [...]
},
"BT5" : {
"text" : "< Back"
}
},
"submit" : {
"*" : [
{
"value" : 5,
"action" : "@menu:demoMain"
}
]
},
"actionKeys" : [
{
"keys" : [ "escape" ],
"viewId" : 5
}
]
}
}
}
},
"demoArtDisplay" : { "demoArtDisplay" : {
"art" : "demo_selection_vm.ans", "art" : "demo_selection_vm.ans",
"options" : { "cls" : true }, "options" : { "cls" : true },

View File

@ -68,10 +68,6 @@ AreaPostFSEModule.prototype.enter = function(client) {
}; };
AreaPostFSEModule.prototype.validateToUserName = function(un, cb) { AreaPostFSEModule.prototype.validateToUserName = function(un, cb) {
console.log('bazinga')
var self = this; var self = this;
if(!self.isLocalEmail()) { if(!self.isLocalEmail()) {

39
mods/msg_list.js Normal file
View File

@ -0,0 +1,39 @@
/* jslint node: true */
'use strict';
var MenuModule = require('../core/menu_module.js').MenuModule;
exports.getModule = MessageListModule;
exports.moduleInfo = {
name : 'Message List',
desc : 'Module for listing/browsing available messages',
author : 'NuSkooler',
};
//
// :TODO:
// * Avail data:
// To
// From
// Subject
// Date
// Status (New/Read)
// Message Num (Area)
// Message Total (Area)
// Message Area desc
// Message Area Name
//
// Ideas
// * Module config can define custom formats for items & focused items (inc. Pipe Codes)
// * Single list view
// *
function MessageListModule(options) {
MenuModule.call(this, options);
var self = this;
}
require('util').inherits(MessageListModule, MenuModule);