* Some WIP on FSE

This commit is contained in:
Bryan Ashby 2015-07-08 22:07:25 -06:00
parent 0fb90b7b10
commit f348e06d86
5 changed files with 126 additions and 44 deletions

View File

@ -53,6 +53,8 @@ var _ = require('lodash');
// * Index pos % for emit scroll events // * Index pos % for emit scroll events
// * Some of this shoudl be async'd where there is lots of processing (e.g. word wrap) // * Some of this shoudl be async'd where there is lots of processing (e.g. word wrap)
// * Fix backspace when col=0 (e.g. bs to prev line) // * Fix backspace when col=0 (e.g. bs to prev line)
// * Add back word delete
// *
var SPECIAL_KEY_MAP_DEFAULT = { var SPECIAL_KEY_MAP_DEFAULT = {

View File

@ -587,7 +587,7 @@ TelnetClient.prototype.handleSbCommand = function(evt) {
// * Map ROWS -> 'termHeight' and only update if ours is 0 // * Map ROWS -> 'termHeight' and only update if ours is 0
// * Add any new variables, ignore any existing // * Add any new variables, ignore any existing
// //
Object.keys(evt.envVars).forEach(function onEnv(name) { Object.keys(evt.envVars || {} ).forEach(function onEnv(name) {
if('TERM' === name && 'unknown' === self.term.termType) { if('TERM' === name && 'unknown' === self.term.termType) {
self.setTermType(evt.envVars[name]); self.setTermType(evt.envVars[name]);
} else if('COLUMNS' === name && 0 === self.term.termWidth) { } else if('COLUMNS' === name && 0 === self.term.termWidth) {

Binary file not shown.

View File

@ -24,40 +24,28 @@ function FullScreenEditorModule(options) {
this.menuConfig = options.menuConfig; this.menuConfig = options.menuConfig;
this.editorType = this.menuConfig.config.editorType; this.editorType = this.menuConfig.config.editorType;
this.artNames = [ 'header', 'body', 'footerEdit', 'footerEditMenu', 'footerView' ]; this.artNames = [ 'header', 'body', 'footerEdit', 'footerEditMenu', 'footerView' ];
this.editorMode = 'edit'; // :TODO: This needs to be passed in via args
this.getFooterName = function(menu) { // :TODO: This needs to be passed in via args:
return true === menu ? this.editorMode = 'edit'; // view | edit | editMenu |
'footerEditMenu' : {
edit : 'footerEdit', this.getFooterName = function(editorMode) {
view : 'footerView', editorMode = editorMode || this.editorMode;
}[self.editorMode]; return 'footer' + _.capitalize(editorMode); // e.g.. 'footerEditMenu'
}; };
this.initSequence = function() { this.getFormId = function(whatFor) {
var mciData = { }; return {
var art = self.menuConfig.config.art; header : 0,
assert(_.isObject(art)); body : 1,
footerEdit : 2,
footerEditMenu : 3,
fotoerView : 4,
}[whatFor];
};
async.series( this.redrawFooter = function(options, cb) {
async.waterfall(
[ [
function beforeDisplayArt(callback) {
self.beforeArt();
callback(null);
},
function displayArtHeaderAndBody(callback) {
assert(_.isString(art.header));
assert(_.isString(art.body));
async.eachSeries( [ 'header', 'body' ], function dispArt(n, next) {
self.displayArtAsset(art[n], function artDisplayed(err, artData) {
mciData[n] = artData;
next(err);
});
}, function complete(err) {
callback(err);
});
},
function moveToFooterPosition(callback) { function moveToFooterPosition(callback) {
// //
// Calculate footer staring position // Calculate footer staring position
@ -71,10 +59,84 @@ function FullScreenEditorModule(options) {
self.client.term.rawWrite(ansi.goto(23, 1)); self.client.term.rawWrite(ansi.goto(23, 1));
callback(null); callback(null);
}, },
function displayArtFooter(callback) { function clearFooterArea(callback) {
var footerName = self.getFooterName(false); if(options.clear) {
self.client.term.rawWrite(ansi.deleteLine(3));
}
callback(null);
},
function displayFooterArt(callback) {
var footerArt = self.menuConfig.config.art[options.footerName];
self.displayArtAsset(art[footerName], function artDisplayed(err, artData) { self.displayArtAsset(footerArt, function artDisplayed(err, artData) {
callback(err, artData);
});
}
],
function complete(err, artData) {
cb(err, artData);
}
);
};
this.switchFooter = function(cb) {
var footerName = self.getFooterName();
self.redrawFooter( { footerName : footerName, clear : true }, function artDisplayed(err, artData) {
if(err) {
cb(err);
return;
}
var formId = self.getFormId(footerName);
if(_.isUndefined(self.viewControllers[footerName])) {
var menuLoadOpts = {
callingMenu : self,
formId : formId,
mciMap : artData.mciMap
};
self.addViewController(
footerName,
new ViewController( { client : self.client, formId : formId } )
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
cb(err);
});
} else {
self.viewControllers[footerName].redrawAll();
cb(null);
}
});
};
this.initSequence = function() {
var mciData = { };
var art = self.menuConfig.config.art;
assert(_.isObject(art));
async.series(
[
function beforeDisplayArt(callback) {
self.beforeArt();
callback(null);
},
function displayHeaderAndBodyArt(callback) {
assert(_.isString(art.header));
assert(_.isString(art.body));
async.eachSeries( [ 'header', 'body' ], function dispArt(n, next) {
self.displayArtAsset(art[n], function artDisplayed(err, artData) {
mciData[n] = artData;
next(err);
});
}, function complete(err) {
callback(err);
});
},
function displayFooter(callback) {
var footerName = self.getFooterName();
self.redrawFooter( { footerName : footerName }, function artDisplayed(err, artData) {
mciData[footerName] = artData; mciData[footerName] = artData;
callback(err); callback(err);
}); });
@ -97,36 +159,36 @@ function FullScreenEditorModule(options) {
async.series( async.series(
[ [
function header(callback) { function header(callback) {
menuLoadOpts.formId = 0; menuLoadOpts.formId = self.getFormId('header');
menuLoadOpts.mciMap = mciData.header.mciMap; menuLoadOpts.mciMap = mciData.header.mciMap;
self.addViewController( self.addViewController(
'header', 'header',
new ViewController( { client : self.client, formId : 0 } ) new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
).loadFromMenuConfig(menuLoadOpts, function headerReady(err) { ).loadFromMenuConfig(menuLoadOpts, function headerReady(err) {
callback(err); callback(err);
}); });
}, },
function body(callback) { function body(callback) {
menuLoadOpts.formId = 1; menuLoadOpts.formId = self.getFormId('body');
menuLoadOpts.mciMap = mciData.body.mciMap; menuLoadOpts.mciMap = mciData.body.mciMap;
self.addViewController( self.addViewController(
'body', 'body',
new ViewController( { client : self.client, formId : 1 } ) new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
).loadFromMenuConfig(menuLoadOpts, function bodyReady(err) { ).loadFromMenuConfig(menuLoadOpts, function bodyReady(err) {
callback(err); callback(err);
}); });
}, },
function footer(callback) { function footer(callback) {
var footerName = self.getFooterName(false); var footerName = self.getFooterName();
menuLoadOpts.formId = 2; menuLoadOpts.formId = self.getFormId(footerName);
menuLoadOpts.mciMap = mciData[footerName].mciMap; menuLoadOpts.mciMap = mciData[footerName].mciMap;
self.addViewController( self.addViewController(
footerName, footerName,
new ViewController( { client : self.client, formId : 2 } ) new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) { ).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
callback(err); callback(err);
}); });
@ -149,7 +211,7 @@ function FullScreenEditorModule(options) {
this.updateEditModePosition = function(pos) { this.updateEditModePosition = function(pos) {
if('edit' === this.editorMode) { if('edit' === this.editorMode) {
var posView = self.viewControllers[self.getFooterName(false)].getView(1); var posView = self.viewControllers.footerEdit.getView(1);
if(posView) { if(posView) {
self.client.term.rawWrite(ansi.savePos()); self.client.term.rawWrite(ansi.savePos());
posView.setText(_.padLeft(String(pos.row + 1), 2, '0') + ',' + _.padLeft(String(pos.col + 1), 2, '0')); posView.setText(_.padLeft(String(pos.row + 1), 2, '0') + ',' + _.padLeft(String(pos.col + 1), 2, '0'));
@ -160,7 +222,7 @@ function FullScreenEditorModule(options) {
this.updateTextEditMode = function(mode) { this.updateTextEditMode = function(mode) {
if('edit' === this.editorMode) { if('edit' === this.editorMode) {
var modeView = self.viewControllers[self.getFooterName(false)].getView(2); var modeView = self.viewControllers.footerEdit.getView(2);
if(modeView) { if(modeView) {
self.client.term.rawWrite(ansi.savePos()); self.client.term.rawWrite(ansi.savePos());
modeView.setText('insert' === mode ? 'INS' : 'OVR'); modeView.setText('insert' === mode ? 'INS' : 'OVR');
@ -172,7 +234,6 @@ function FullScreenEditorModule(options) {
this.menuMethods = { this.menuMethods = {
headerSubmit : function(formData, extraArgs) { headerSubmit : function(formData, extraArgs) {
// console.log('submit header:\n' + JSON.stringify(self.viewControllers.header.getFormData()))
self.viewControllers.header.removeFocus(); self.viewControllers.header.removeFocus();
self.viewControllers.body.switchFocus(1); self.viewControllers.body.switchFocus(1);
@ -185,7 +246,17 @@ function FullScreenEditorModule(options) {
}); });
}, },
editorEscPressed : function(formData, extraArgs) { editorEscPressed : function(formData, extraArgs) {
//this.editorMode = 'edit' === this.editorMode ? 'editMenu' : 'edit';
self.editorMode = 'editMenu';
self.switchFooter(function next(err) {
if(err) {
// :TODO:... what now?
console.log(err)
} else {
self.viewControllers.body.removeFocus();
self.viewControllers.footerEditMenu.switchFocus(1);
}
});
} }
}; };
} }

View File

@ -540,6 +540,15 @@
} }
} }
} }
},
"3" : {
"HM1" : {
"mci" : {
"HM1" : {
"items" : [ "Menu 1", "Menu 2", "Menu 3", "Menu 4" ]
}
}
}
} }
} }
/* /*