* Lots of WIP on FSE demo

* WIP emit position from MutliLineEditTextView
* ansi.rawWrite() when no iconv/lfs to be processed
This commit is contained in:
Bryan Ashby 2015-07-05 19:05:55 -06:00
parent 60cae7de3d
commit 3d5d21bcb5
17 changed files with 223 additions and 80 deletions

6
README.md Normal file
View File

@ -0,0 +1,6 @@
Special Thanks
* M. Brutman, author of mTCP (http://www.brutman.com/mTCP/mTCP.html)
* M. Griffin, author of Enthral BBS (https://github.com/M-griffin/Enthral)

View File

@ -77,11 +77,6 @@ var CONTROL = {
// apparently some terms can report screen size and text area via 18t and 19t // apparently some terms can report screen size and text area via 18t and 19t
}; };
/*
DECTERM stuff. Probably never need
hide : '?25l',
show : '?25h',*/
// //
// Select Graphics Rendition // Select Graphics Rendition
// See http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/src/conio/cterm.txt // See http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/src/conio/cterm.txt

View File

@ -426,6 +426,7 @@ function display(options, cb) {
var generatedId = 100; var generatedId = 100;
var cprListener = function(pos) { var cprListener = function(pos) {
console.log(pos)
if(mciPosQueue.length > 0) { if(mciPosQueue.length > 0) {
var forMapItem = mciPosQueue.shift(); var forMapItem = mciPosQueue.shift();
mciMap[forMapItem].position = pos; mciMap[forMapItem].position = pos;
@ -437,6 +438,7 @@ function display(options, cb) {
}; };
function completed() { function completed() {
console.log('completed')
options.client.removeListener('cursor position report', cprListener); options.client.removeListener('cursor position report', cprListener);
parser.removeAllListeners(); // :TODO: Necessary??? parser.removeAllListeners(); // :TODO: Necessary???
@ -507,7 +509,8 @@ function display(options, cb) {
mciPosQueue.push(mapKey); mciPosQueue.push(mapKey);
options.client.term.write(ansi.queryPos(), false); // :TODO: don't convert LF's console.log('querying pos...')
options.client.term.rawWrite(ansi.queryPos());
} }
}); });
@ -542,12 +545,12 @@ function display(options, cb) {
} }
if(ansiFont.length > 1) { if(ansiFont.length > 1) {
options.client.term.write(ansiFont); options.client.term.rawWrite(ansiFont);
} }
if(iceColors) { if(iceColors) {
options.client.term.write(ansi.blinkToBrightIntensity()); options.client.term.rawWrite(ansi.blinkToBrightIntensity());
} }
parser.reset(options.art); parser.reset(options.art);

View File

@ -107,10 +107,28 @@ ClientTerminal.prototype.isANSI = function() {
return [ 'ansi', 'pc-ansi', 'qansi', 'scoansi' ].indexOf(this.termType) > -1; return [ 'ansi', 'pc-ansi', 'qansi', 'scoansi' ].indexOf(this.termType) > -1;
}; };
/*
ClientTerminal.prototype.write = function(s, convertLineFeeds) { ClientTerminal.prototype.write = function(s, convertLineFeeds) {
convertLineFeeds = _.isUndefined(convertLineFeeds) ? this.convertLF : convertLineFeeds; convertLineFeeds = _.isUndefined(convertLineFeeds) ? this.convertLF : convertLineFeeds;
if(convertLineFeeds && _.isString(s)) { if(convertLineFeeds && _.isString(s)) {
s = s.replace(/\n/g, '\r\n'); s = s.replace(/\n/g, '\r\n');
} }
this.output.write(iconv.encode(s, this.outputEncoding)); this.output.write(this.iconv.encode(s, this.outputEncoding));
}; };
*/
ClientTerminal.prototype.write = function(s, convertLineFeeds) {
this.output.write(this.encode(s, convertLineFeeds));
};
ClientTerminal.prototype.rawWrite = function(s) {
this.output.write(s);
};
ClientTerminal.prototype.encode = function(s, convertLineFeeds) {
convertLineFeeds = _.isUndefined(convertLineFeeds) ? this.convertLF : convertLineFeeds;
if(convertLineFeeds && _.isString(s)) {
s = s.replace(/\n/g, '\r\n');
}
return iconv.encode(s, this.outputEncoding);
};

View File

@ -5,8 +5,8 @@ var ansi = require('./ansi_term.js');
var assert = require('assert'); var assert = require('assert');
exports.pipeToAnsi = exports.renegadeToAnsi = renegadeToAnsi; exports.pipeToAnsi = exports.enigmaToAnsi = enigmaToAnsi;
exports.stripPipeCodes = exports.stripRenegadeCodes = stripRenegadeCodes; exports.stripPipeCodes = exports.stripEnigmaCodes = stripEnigmaCodes;
// :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
@ -19,6 +19,50 @@ exports.stripPipeCodes = exports.stripRenegadeCodes = stripRenegadeCodes;
// * fromWWIV(): <ctrl-c><0-7> // * fromWWIV(): <ctrl-c><0-7>
// * fromSyncronet(): <ctrl-a><colorCode> // * fromSyncronet(): <ctrl-a><colorCode>
// See http://wiki.synchro.net/custom:colors // See http://wiki.synchro.net/custom:colors
function enigmaToAnsi(s) {
if(-1 == s.indexOf('|')) {
return s; // no pipe codes present
}
var result = '';
var re = /\|(\d{2}|\|)/g;
var m;
var lastIndex = 0;
while((m = re.exec(s))) {
var val = m[1];
if('|' == val) {
result += '|';
continue;
}
// convert to number
val = parseInt(val, 10);
if(isNaN(val)) {
val = 0;
}
assert(val >= 0 && val <= 47);
var attr = '';
if(7 == val) {
attr = ansi.sgr('normal');
} else if (val < 7 || val >= 16) {
attr = ansi.sgr(['normal', val]);
} else if (val <= 15) {
attr = ansi.sgr(['normal', val - 8, 'bold']);
}
result += s.substr(lastIndex, m.index - lastIndex) + attr;
lastIndex = re.lastIndex;
}
result = (0 === result.length ? s : result + s.substr(lastIndex));
return result;
}
// :TODO: NYI
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
@ -42,7 +86,7 @@ function renegadeToAnsi(s) {
val = 0; val = 0;
} }
assert(val >= 0 && val <= 256); // :TODO: should be <= 23 I believe assert(val >= 0 && val <= 23);
var attr = ''; var attr = '';
if(7 == val) { if(7 == val) {
@ -62,7 +106,7 @@ function renegadeToAnsi(s) {
return result; return result;
} }
function stripRenegadeCodes(s) { function stripEnigmaCodes(s) {
return s.replace(/\|[\d]{2}/g, ''); return s.replace(/\|[\d]{2}/g, '');
} }

View File

@ -5,7 +5,6 @@ var ansi = require('./ansi_term.js');
var colorCodes = require('./color_codes.js'); var colorCodes = require('./color_codes.js');
var theme = require('./theme.js'); var theme = require('./theme.js');
var moduleUtil = require('./module_util.js'); var moduleUtil = require('./module_util.js');
//var Log = require('./logger.js').log;
var Config = require('./config.js').config; var Config = require('./config.js').config;

View File

@ -117,6 +117,7 @@ function MenuModule(options) {
], ],
function complete(err) { function complete(err) {
if(err) { if(err) {
console.log(err)
// :TODO: what to do exactly????? // :TODO: what to do exactly?????
} }

View File

@ -142,35 +142,37 @@ function MultiLineEditTextView(options) {
}; };
this.redrawRows = function(startRow, endRow) { this.redrawRows = function(startRow, endRow) {
self.client.term.write(self.getSGRFor('text') + ansi.hideCursor()); self.client.term.rawWrite(self.getSGRFor('text') + ansi.hideCursor());
var startIndex = self.getTextLinesIndex(startRow); var startIndex = self.getTextLinesIndex(startRow);
var endIndex = Math.min(self.getTextLinesIndex(endRow), self.textLines.length); var endIndex = Math.min(self.getTextLinesIndex(endRow), self.textLines.length);
var absPos = self.getAbsolutePosition(startRow, 0); var absPos = self.getAbsolutePosition(startRow, 0);
for(var i = startIndex; i < endIndex; ++i) { for(var i = startIndex; i < endIndex; ++i) {
self.client.term.write(ansi.goto(absPos.row++, absPos.col)); self.client.term.write(
self.client.term.write(self.getRenderText(i)); ansi.goto(absPos.row++, absPos.col) +
self.getRenderText(i), false);
} }
self.client.term.write(ansi.showCursor()); self.client.term.rawWrite(ansi.showCursor());
return absPos.row - self.position.row; // row we ended on return absPos.row - self.position.row; // row we ended on
}; };
this.eraseRows = function(startRow, endRow) { this.eraseRows = function(startRow, endRow) {
self.client.term.write(self.getSGRFor('text') + ansi.hideCursor()); self.client.term.rawWrite(self.getSGRFor('text') + ansi.hideCursor());
var absPos = self.getAbsolutePosition(startRow, 0); var absPos = self.getAbsolutePosition(startRow, 0);
var absPosEnd = self.getAbsolutePosition(endRow, 0); var absPosEnd = self.getAbsolutePosition(endRow, 0);
var eraseFiller = new Array(self.dimens.width).join(' '); var eraseFiller = new Array(self.dimens.width).join(' ');
while(absPos.row < absPosEnd.row) { while(absPos.row < absPosEnd.row) {
self.client.term.write(ansi.goto(absPos.row++, absPos.col)); self.client.term.write(
self.client.term.write(eraseFiller); ansi.goto(absPos.row++, absPos.col) +
eraseFiller, false);
} }
self.client.term.write(ansi.showCursor()); self.client.term.rawWrite(ansi.showCursor());
}; };
this.redrawVisibleArea = function() { this.redrawVisibleArea = function() {
@ -409,13 +411,13 @@ function MultiLineEditTextView(options) {
console.log('cursorOffset=' + cursorOffset) console.log('cursorOffset=' + cursorOffset)
self.cursorBeginOfNextLine(); self.cursorBeginOfNextLine();
self.cursorPos.col += cursorOffset; self.cursorPos.col += cursorOffset;
self.client.term.write(ansi.right(cursorOffset)); self.client.term.rawWrite(ansi.right(cursorOffset));
} else { } else {
self.cursorPos.row++; self.cursorPos.row++;
self.cursorPos.col = 1; // we just added 1 char self.cursorPos.col = 1; // we just added 1 char
absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col); absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col);
console.log('absPos=' + JSON.stringify(absPos)) console.log('absPos=' + JSON.stringify(absPos))
self.client.term.write(ansi.goto(absPos.row, absPos.col)); self.client.term.rawWrite(ansi.goto(absPos.row, absPos.col));
} }
} else { } else {
// //
@ -428,7 +430,7 @@ function MultiLineEditTextView(options) {
self.getSGRFor('text') + self.getSGRFor('text') +
self.getRenderText(index).slice(self.cursorPos.col - c.length) + self.getRenderText(index).slice(self.cursorPos.col - c.length) +
ansi.goto(absPos.row, absPos.col) + ansi.goto(absPos.row, absPos.col) +
ansi.showCursor() ansi.showCursor(), false
); );
} }
}; };
@ -602,7 +604,7 @@ function MultiLineEditTextView(options) {
this.moveClientCusorToCursorPos = function() { this.moveClientCusorToCursorPos = function() {
var absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col); var absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col);
self.client.term.write(ansi.goto(absPos.row, absPos.col)); self.client.term.rawWrite(ansi.goto(absPos.row, absPos.col));
}; };
@ -633,12 +635,13 @@ function MultiLineEditTextView(options) {
}*/ }*/
} }
self.emitPosition();
}; };
this.keyPressUp = function() { this.keyPressUp = function() {
if(self.cursorPos.row > 0) { if(self.cursorPos.row > 0) {
self.cursorPos.row--; self.cursorPos.row--;
self.client.term.write(ansi.up()); self.client.term.rawWrite(ansi.up());
if(!self.adjustCursorToNextTab('up')) { if(!self.adjustCursorToNextTab('up')) {
self.adjustCursorIfPastEndOfLine(false); self.adjustCursorIfPastEndOfLine(false);
@ -647,6 +650,8 @@ function MultiLineEditTextView(options) {
self.scrollDocumentDown(); self.scrollDocumentDown();
self.adjustCursorIfPastEndOfLine(true); self.adjustCursorIfPastEndOfLine(true);
} }
self.emitPosition();
}; };
this.keyPressDown = function() { this.keyPressDown = function() {
@ -656,7 +661,7 @@ function MultiLineEditTextView(options) {
if(self.cursorPos.row < lastVisibleRow) { if(self.cursorPos.row < lastVisibleRow) {
self.cursorPos.row++; self.cursorPos.row++;
self.client.term.write(ansi.down()); self.client.term.rawWrite(ansi.down());
if(!self.adjustCursorToNextTab('down')) { if(!self.adjustCursorToNextTab('down')) {
self.adjustCursorIfPastEndOfLine(false); self.adjustCursorIfPastEndOfLine(false);
@ -665,6 +670,8 @@ function MultiLineEditTextView(options) {
self.scrollDocumentUp(); self.scrollDocumentUp();
self.adjustCursorIfPastEndOfLine(true); self.adjustCursorIfPastEndOfLine(true);
} }
self.emitPosition();
}; };
this.keyPressLeft = function() { this.keyPressLeft = function() {
@ -672,7 +679,7 @@ function MultiLineEditTextView(options) {
var prevCharIsTab = self.isTab(); var prevCharIsTab = self.isTab();
self.cursorPos.col--; self.cursorPos.col--;
self.client.term.write(ansi.left()); self.client.term.rawWrite(ansi.left());
if(prevCharIsTab) { if(prevCharIsTab) {
self.adjustCursorToNextTab('left'); self.adjustCursorToNextTab('left');
@ -680,6 +687,8 @@ function MultiLineEditTextView(options) {
} else { } else {
self.cursorEndOfPreviousLine(); self.cursorEndOfPreviousLine();
} }
self.emitPosition();
}; };
this.keyPressRight = function() { this.keyPressRight = function() {
@ -688,7 +697,7 @@ function MultiLineEditTextView(options) {
var prevCharIsTab = self.isTab(); var prevCharIsTab = self.isTab();
self.cursorPos.col++; self.cursorPos.col++;
self.client.term.write(ansi.right()); self.client.term.rawWrite(ansi.right());
if(prevCharIsTab) { if(prevCharIsTab) {
self.adjustCursorToNextTab('right'); self.adjustCursorToNextTab('right');
@ -696,6 +705,8 @@ function MultiLineEditTextView(options) {
} else { } else {
self.cursorBeginOfNextLine(); self.cursorBeginOfNextLine();
} }
self.emitPosition();
}; };
this.keyPressHome = function() { this.keyPressHome = function() {
@ -707,11 +718,14 @@ function MultiLineEditTextView(options) {
} }
console.log('"' + self.getVisibleText() + '"') console.log('"' + self.getVisibleText() + '"')
self.moveClientCusorToCursorPos(); self.moveClientCusorToCursorPos();
self.emitPosition();
}; };
this.keyPressEnd = function() { this.keyPressEnd = function() {
self.cursorPos.col = self.getTextEndOfLineColumn(); self.cursorPos.col = self.getTextEndOfLineColumn();
self.moveClientCusorToCursorPos(); self.moveClientCusorToCursorPos();
self.emitPosition();
}; };
this.keyPressPageUp = function() { this.keyPressPageUp = function() {
@ -723,6 +737,8 @@ function MultiLineEditTextView(options) {
self.cursorPos.row = 0; self.cursorPos.row = 0;
self.moveClientCusorToCursorPos(); // :TODO: ajust if eol, etc. self.moveClientCusorToCursorPos(); // :TODO: ajust if eol, etc.
} }
self.emitPosition();
}; };
this.keyPressPageDown = function() { this.keyPressPageDown = function() {
@ -732,6 +748,8 @@ function MultiLineEditTextView(options) {
self.redraw(); self.redraw();
self.adjustCursorIfPastEndOfLine(true); self.adjustCursorIfPastEndOfLine(true);
} }
self.emitPosition();
}; };
this.keyPressLineFeed = function() { this.keyPressLineFeed = function() {
@ -757,6 +775,8 @@ function MultiLineEditTextView(options) {
// redraw from current row to end of visible area // redraw from current row to end of visible area
self.redrawRows(self.cursorPos.row, self.dimens.height); self.redrawRows(self.cursorPos.row, self.dimens.height);
self.cursorBeginOfNextLine(); self.cursorBeginOfNextLine();
self.emitPosition();
}; };
this.keyPressInsert = function() { this.keyPressInsert = function() {
@ -767,6 +787,8 @@ function MultiLineEditTextView(options) {
this.keyPressTab = function() { this.keyPressTab = function() {
var index = self.getTextLinesIndex(); var index = self.getTextLinesIndex();
self.insertCharactersInText(self.expandTab(self.cursorPos.col, '\t') + '\t', index, self.cursorPos.col); self.insertCharactersInText(self.expandTab(self.cursorPos.col, '\t') + '\t', index, self.cursorPos.col);
self.emitPosition();
}; };
this.keyPressBackspace = function() { this.keyPressBackspace = function() {
@ -810,6 +832,8 @@ function MultiLineEditTextView(options) {
self.keyPressLeft(); // same as hitting left - jump to previous line self.keyPressLeft(); // same as hitting left - jump to previous line
//self.keyPressBackspace(); //self.keyPressBackspace();
} }
self.emitPosition();
}; };
this.keyPressDelete = function() { this.keyPressDelete = function() {
@ -818,6 +842,8 @@ function MultiLineEditTextView(options) {
self.cursorPos.col, self.cursorPos.col,
'right', 'right',
1); 1);
self.emitPosition();
}; };
//this.keyPressClearLine = function() { //this.keyPressClearLine = function() {
@ -828,6 +854,8 @@ function MultiLineEditTextView(options) {
0, 0,
'delete line'); 'delete line');
} }
self.emitPosition();
}; };
this.adjustCursorIfPastEndOfLine = function(forceUpdate) { this.adjustCursorIfPastEndOfLine = function(forceUpdate) {
@ -852,7 +880,7 @@ function MultiLineEditTextView(options) {
case 'right' : case 'right' :
move = self.getNextTabStop(self.cursorPos.col) - self.cursorPos.col; move = self.getNextTabStop(self.cursorPos.col) - self.cursorPos.col;
self.cursorPos.col += move; self.cursorPos.col += move;
self.client.term.write(ansi.right(move)); self.client.term.rawWrite(ansi.right(move));
break; break;
// //
@ -861,7 +889,7 @@ function MultiLineEditTextView(options) {
case 'left' : case 'left' :
move = self.cursorPos.col - self.getPrevTabStop(self.cursorPos.col); move = self.cursorPos.col - self.getPrevTabStop(self.cursorPos.col);
self.cursorPos.col -= move; self.cursorPos.col -= move;
self.client.term.write(ansi.left(move)); self.client.term.rawWrite(ansi.left(move));
break; break;
case 'up' : case 'up' :
@ -876,11 +904,11 @@ function MultiLineEditTextView(options) {
if(newCol > self.cursorPos.col) { if(newCol > self.cursorPos.col) {
move = newCol - self.cursorPos.col; move = newCol - self.cursorPos.col;
self.cursorPos.col += move; self.cursorPos.col += move;
self.client.term.write(ansi.right(move)); self.client.term.rawWrite(ansi.right(move));
} else if(newCol < self.cursorPos.col) { } else if(newCol < self.cursorPos.col) {
move = self.cursorPos.col - newCol; move = self.cursorPos.col - newCol;
self.cursorPos.col -= move; self.cursorPos.col -= move;
self.client.term.write(ansi.left(move)); self.client.term.rawWrite(ansi.left(move));
} }
break; break;
} }
@ -977,6 +1005,12 @@ function MultiLineEditTextView(options) {
} }
}; };
this.emitPosition = function() {
self.emit(
'cursor position',
{ row : self.getTextLinesIndex(self.cursorPos.row), col : self.cursorPos.col });
};
} }
require('util').inherits(MultiLineEditTextView, View); require('util').inherits(MultiLineEditTextView, View);
@ -994,7 +1028,7 @@ MultiLineEditTextView.prototype.redraw = function() {
}; };
MultiLineEditTextView.prototype.setFocus = function(focused) { MultiLineEditTextView.prototype.setFocus = function(focused) {
this.client.term.write(this.getSGRFor('text')); this.client.term.rawWrite(this.getSGRFor('text'));
this.moveClientCusorToCursorPos(); this.moveClientCusorToCursorPos();
MultiLineEditTextView.super_.prototype.setFocus.call(this, focused); MultiLineEditTextView.super_.prototype.setFocus.call(this, focused);

View File

@ -81,7 +81,7 @@ function TextView(options) {
this.justify, this.justify,
this.hasFocus ? this.getFocusSGR() : this.getSGR(), this.hasFocus ? this.getFocusSGR() : this.getSGR(),
this.getStyleSGR(1) || this.getSGR() this.getStyleSGR(1) || this.getSGR()
)); ), false);
}; };
this.getEndOfTextColumn = function() { this.getEndOfTextColumn = function() {

View File

@ -54,13 +54,12 @@ function VerticalMenuView(options) {
return; return;
} }
self.client.term.write(ansi.goto(item.row, self.position.col));
self.client.term.write(index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR());
var text = strUtil.stylizeString(item.text, item.focused ? self.focusTextStyle : self.textStyle); var text = strUtil.stylizeString(item.text, item.focused ? self.focusTextStyle : self.textStyle);
self.client.term.write( self.client.term.write(
strUtil.pad(text, this.dimens.width, this.fillChar, this.justify)); ansi.goto(item.row, self.position.col) +
(index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR()) +
strUtil.pad(text, this.dimens.width, this.fillChar, this.justify)
);
}; };
} }

View File

@ -93,12 +93,12 @@ function View(options) {
}; };
this.hideCusor = function() { this.hideCusor = function() {
self.client.term.write(ansi.hideCursor()); self.client.term.rawWrite(ansi.hideCursor());
}; };
this.restoreCursor = function() { this.restoreCursor = function() {
//this.client.term.write(ansi.setCursorStyle(this.cursorStyle)); //this.client.term.write(ansi.setCursorStyle(this.cursorStyle));
this.client.term.write('show' === this.cursor ? ansi.showCursor() : ansi.hideCursor()); this.client.term.rawWrite('show' === this.cursor ? ansi.showCursor() : ansi.hideCursor());
}; };
} }

View File

@ -305,7 +305,7 @@ ViewController.prototype.setViewOrder = function(order) {
}; };
ViewController.prototype.redrawAll = function(initialFocusId) { ViewController.prototype.redrawAll = function(initialFocusId) {
this.client.term.write(ansi.hideCursor()); this.client.term.rawWrite(ansi.hideCursor());
for(var id in this.views) { for(var id in this.views) {
if(initialFocusId === id) { if(initialFocusId === id) {
@ -314,7 +314,7 @@ ViewController.prototype.redrawAll = function(initialFocusId) {
this.views[id].redraw(); this.views[id].redraw();
} }
this.client.term.write(ansi.showCursor()); this.client.term.rawWrite(ansi.showCursor());
}; };
ViewController.prototype.loadFromPromptConfig = function(options, cb) { ViewController.prototype.loadFromPromptConfig = function(options, cb) {

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,7 @@
var MenuModule = require('../core/menu_module.js').MenuModule; var MenuModule = require('../core/menu_module.js').MenuModule;
var ViewController = require('../core/view_controller.js').ViewController; var ViewController = require('../core/view_controller.js').ViewController;
var ansi = require('../core/ansi_term.js');
var async = require('async'); var async = require('async');
var assert = require('assert'); var assert = require('assert');
@ -25,30 +26,25 @@ function FullScreenEditorModule(options) {
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.editorMode = 'edit'; // :TODO: This needs to be passed in via args
this.getFooterName = function(menu) {
return true === menu ?
'footerEditMenu' : {
edit : 'footerEdit',
view : 'footerView',
}[self.editorMode];
};
this.initSequence = function() { this.initSequence = function() {
var mciData = { }; var mciData = { };
var art = self.menuConfig.config.art; var art = self.menuConfig.config.art;
assert(_.isObject(art)); assert(_.isObject(art));
// :TODO: async.series here? async.series(
async.waterfall(
[ [
function beforeDisplayArt(callback) { function beforeDisplayArt(callback) {
self.beforeArt(); self.beforeArt();
callback(null); callback(null);
}, },
/*
function displayMainArt(callback) {
if(_.isString(self.menuConfig.art)) {
self.displayArtAsset(self.menuConfig.art, function frameDisplayed(err, artData) {
mciData.main = artData;
callback(err);
});
} else {
callback(null); // :TODO: should probably throw error... can't do much without this
}
},
*/
function displayArtHeaderAndBody(callback) { function displayArtHeaderAndBody(callback) {
assert(_.isString(art.header)); assert(_.isString(art.header));
assert(_.isString(art.body)); assert(_.isString(art.body));
@ -62,9 +58,27 @@ function FullScreenEditorModule(options) {
callback(err); callback(err);
}); });
}, },
function displayArtFooter(callback) { function moveToFooterPosition(callback) {
//
// Calculate footer staring position
//
// row = (header height + body height)
//
// Header: mciData.body.height
// Body : We must find this in the config / theme
//
// :TODO: don't hard code this -- allow footer to be themed/etc.
self.client.term.rawWrite(ansi.goto(23, 1));
callback(null); callback(null);
}, },
function displayArtFooter(callback) {
var footerName = self.getFooterName(false);
self.displayArtAsset(art[footerName], function artDisplayed(err, artData) {
mciData[footerName] = artData;
callback(err);
});
},
function afterArtDisplayed(callback) { function afterArtDisplayed(callback) {
self.mciReady(mciData); self.mciReady(mciData);
callback(null); callback(null);
@ -88,7 +102,7 @@ function FullScreenEditorModule(options) {
self.addViewController( self.addViewController(
'header', 'header',
new ViewController( { client : self.client } ) new ViewController( { client : self.client, formId : 0 } )
).loadFromMenuConfig(menuLoadOpts, function headerReady(err) { ).loadFromMenuConfig(menuLoadOpts, function headerReady(err) {
callback(err); callback(err);
}); });
@ -99,10 +113,23 @@ function FullScreenEditorModule(options) {
self.addViewController( self.addViewController(
'body', 'body',
new ViewController( { client : self.client } ) new ViewController( { client : self.client, formId : 1 } )
).loadFromMenuConfig(menuLoadOpts, function bodyReady(err) { ).loadFromMenuConfig(menuLoadOpts, function bodyReady(err) {
callback(err); callback(err);
}); });
},
function footer(callback) {
var footerName = self.getFooterName(false);
menuLoadOpts.formId = 2;
menuLoadOpts.mciMap = mciData[footerName].mciMap;
self.addViewController(
footerName,
new ViewController( { client : self.client, formId : 2 } )
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
callback(err);
});
} }
], ],
function complete(err) { function complete(err) {
@ -112,25 +139,30 @@ function FullScreenEditorModule(options) {
); );
}; };
/* this.getBodyView = function() {
this.mciReadyHandlerNetMail = function(mciData) { return self.viewControllers.body.getView(1);
var mainVc = self.addViewController('main', new ViewController( { client : self.client } ));
var menuLoadOpts = {
callingMenu : self,
mciMap : mciData.main.mciMap,
formId : 0,
}; };
mainVc.loadFromMenuConfig(menuLoadOpts, function viewsReady(err) { this.updateEditModePosition = function(pos) {
}); if('edit' === this.editorMode) {
var posView = self.viewControllers[self.getFooterName(false)].getView(1);
if(posView) {
posView.setText(pos.row + ',' + pos.col);
self.getBodyView().setFocus(true);
}
}
}; };
*/
this.menuMethods = { this.menuMethods = {
headerSubmit : function(formData, extraArgs) { headerSubmit : function(formData, extraArgs) {
console.log('submit header:\n' + JSON.stringify(self.viewControllers.header.getFormData())) // console.log('submit header:\n' + JSON.stringify(self.viewControllers.header.getFormData()))
self.viewControllers.header.removeFocus();
self.viewControllers.body.switchFocus(1); self.viewControllers.body.switchFocus(1);
self.getBodyView().on('cursor position', function cursorPosUpdate(pos) {
self.updateEditModePosition(pos);
});
}, },
editorEscPressed : function(formData, extraArgs) { editorEscPressed : function(formData, extraArgs) {

View File

@ -514,7 +514,7 @@
"mci" : { "mci" : {
"MT1" : { "MT1" : {
"width" : 79, "width" : 79,
"height" : 16, "height" : 17,
"text" : "", // :TODO: should not be req. "text" : "", // :TODO: should not be req.
"submit" : [ "escape" ] "submit" : [ "escape" ]
} }
@ -528,6 +528,18 @@
] ]
} }
} }
},
"2" : {
"TL1TL2" : {
"mci" : {
"TL1" : {
"width" : 5
},
"TL2" : {
"width" : 4
}
}
}
} }
} }
/* /*