* Progress on FSE / Area Posting

* Proof of concept work on user validation in FSE
* Term now has pipeWrite()
This commit is contained in:
Bryan Ashby 2015-08-19 22:10:18 -06:00
parent ca26cca55b
commit ec70cc8caa
8 changed files with 96 additions and 28 deletions

View File

@ -2,11 +2,12 @@
'use strict';
// ENiGMA½
var Log = require('./logger.js').log;
var Log = require('./logger.js').log;
var enigmaToAnsi = require('./color_codes.js').enigmaToAnsi;
var iconv = require('iconv-lite');
var assert = require('assert');
var _ = require('lodash');
var iconv = require('iconv-lite');
var assert = require('assert');
var _ = require('lodash');
iconv.extendNodeEncodings();
@ -126,16 +127,6 @@ ClientTerminal.prototype.isANSI = function() {
return [ 'ansi', 'pc-ansi', 'qansi', 'scoansi' ].indexOf(this.termType) > -1;
};
/*
ClientTerminal.prototype.write = function(s, convertLineFeeds) {
convertLineFeeds = _.isUndefined(convertLineFeeds) ? this.convertLF : convertLineFeeds;
if(convertLineFeeds && _.isString(s)) {
s = s.replace(/\n/g, '\r\n');
}
this.output.write(this.iconv.encode(s, this.outputEncoding));
};
*/
// :TODO: probably need to update these to convert IAC (0xff) -> IACIAC (escape it)
ClientTerminal.prototype.write = function(s, convertLineFeeds) {
@ -146,6 +137,10 @@ ClientTerminal.prototype.rawWrite = function(s) {
this.output.write(s);
};
ClientTerminal.prototype.pipeWrite = function(s) {
this.write(enigmaToAnsi(s));
};
ClientTerminal.prototype.encode = function(s, convertLineFeeds) {
convertLineFeeds = _.isUndefined(convertLineFeeds) ? this.convertLF : convertLineFeeds;
if(convertLineFeeds && _.isString(s)) {

View File

@ -2,7 +2,6 @@
'use strict';
var ansi = require('./ansi_term.js');
var colorCodes = require('./color_codes.js');
var theme = require('./theme.js');
var moduleUtil = require('./module_util.js');
var Config = require('./config.js').config;
@ -75,21 +74,21 @@ function ansiQueryTermSizeIfNeeded(client, cb) {
}, 2000);
// This causes
client.term.write(ansi.queryScreenSize());
client.term.rawWrite(ansi.queryScreenSize());
}
function prepareTerminal(term) {
term.write(ansi.normal());
term.write(ansi.disableVT100LineWrapping());
term.rawWrite(ansi.normal());
term.rawWrite(ansi.disableVT100LineWrapping());
// :TODO: set xterm stuff -- see x84/others
}
function displayBanner(term) {
// :TODO: add URL(s) to banner
term.write(colorCodes.pipeToAnsi(util.format(
term.pipeWrite(util.format(
'|33Conected to |32EN|33|01i|00|32|22GMA|32|01½|00 |33BBS version|31|01 %s\n' +
'|00|33Copyright (c) 2014-2015 Bryan Ashby |33|01- |31|01http://l33t.codes/\n' +
'|00', packageJson.version)));
'|00', packageJson.version));
}
function connectEntry(client) {

View File

@ -47,8 +47,9 @@ function FullScreenEditorModule(options) {
this.messageAreaId = options.extraArgs.messageAreaId || Message.WellKnownAreaIds.Private;
}
// netMail/crashMail | echoMail
//this.messageAreaId = 'netMail' === this.editorType ? Message.WellKnownAreaIds.Private : options.messageAreaId;
this.isLocalEmail = function() {
return 'email' === this.editorType && Message.WellKnownAreaIds.Private === this.messageAreaId;
};
this.getFooterName = function(editorMode) {
editorMode = editorMode || this.editorMode;
@ -312,7 +313,18 @@ function FullScreenEditorModule(options) {
this.mciReadyHandler = function(mciData) {
self.createInitialViews(mciData, function viewsCreated(err) {
self.viewControllers.header.on('leave', function headerViewLeave(view) {
if(2 === view.id) { // "to" field
self.validateToUserName(view.getData(), function result(err) {
if(err) {
// :TODO: display a error in a %TL area or such
view.clearText();
self.viewControllers.headers.switchFocus(2);
}
});
}
});
});
};
@ -460,3 +472,7 @@ FullScreenEditorModule.prototype.mciReady = function(mciData) {
//this['mciReadyHandler' + _.capitalize(this.editorType)](mciData);
};
FullScreenEditorModule.prototype.validateToUserName = function(un, cb) {
cb(null); // note: to be implemented by sub classes
};

View File

@ -37,7 +37,11 @@ function Message(options) {
_.defaultsDeep(this.meta, options.meta);
}
this.meta = options.meta || {};
if(options.meta) {
this.meta = options.meta;
}
// this.meta = options.meta || {};
this.hashTags = options.hashTags || [];
var self = this;

Binary file not shown.

View File

@ -316,6 +316,7 @@
"messageAreaNewPost" : {
"module" : "msg_area_post_fse",
"options" : { "cls" : true },
"fallback" : "messageArea", // :TODO: remove once default fallback is in place
"config" : {
"art" : {
"header" : "msg_area_post_header",
@ -324,11 +325,12 @@
"footerEditMenu" : "demo_fse_netmail_footer_edit_menu.ans",
"footerView" : "demo_fse_netmail_footer_view.ans",
"help" : "demo_fse_netmail_help.ans"
}
},
"editorType" : "area"
},
"form" : {
"0" : {
"ETETTLTL" : {
"ETETTL" : {
"mci" : {
"TL1" : {
"width" : 36,
@ -345,10 +347,15 @@
"maxLength" : 72,
"submit" : true
},
"TL4" : {
"MA5" : {
"width" : 19,
"textOverflow" : "..."
}
/*,
"TL4" : {
"width" : 19,
"textOverflow" : "..."
}*/
},
"submit" : {
"3" : [

View File

@ -36,9 +36,10 @@ function MessageAreaListModule(options) {
changeArea : function(formData, extraArgs) {
if(1 === formData.submitId) {
var areaId = self.messageAreas[formData.value.area].areaId;
messageArea.changeCurrentArea(self.client, areaId, function areaChanged(err) {
if(err) {
self.client.term.write('\nCannot change area: ' + err.message + '\n');
self.client.term.pipeWrite('\n|00Cannot change area: ' + err.message + '\n');
setTimeout(function timeout() {
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );

View File

@ -3,8 +3,10 @@
var FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
var Message = require('../core/message.js').Message;
var user = require('../core/user.js');
var _ = require('lodash');
var async = require('async');
exports.getModule = AreaPostFSEModule;
@ -24,7 +26,33 @@ function AreaPostFSEModule(options) {
this.menuMethods.editModeMenuSave = function(formData, extraArgs) {
var msg = self.getMessage();
console.log(msg);
async.series(
[
function prepareMessage(callback) {
if(self.isLocalEmail()) {
msg.setLocalFromUserId(self.client.user.userId);
msg.setLocalToUserId(self.toUserId);
}
callback(null);
},
function saveMessage(callback) {
msg.persist(function persisted(err) {
callback(err);
});
}
],
function complete(err) {
if(err) {
// :TODO:... sooooo now what?
} else {
console.log(msg);
}
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
}
);
};
}
@ -41,3 +69,21 @@ AreaPostFSEModule.prototype.enter = function(client) {
AreaPostFSEModule.super_.prototype.enter.call(this, client);
};
AreaPostFSEModule.prototype.validateToUserName = function(un, cb) {
console.log('bazinga')
var self = this;
if(!self.isLocalEmail()) {
cb(null);
return;
}
user.getUserIdAndName(un, function uidAndName(err, userId, userName) {
self.toUserId = userId;
cb(err);
});
};