* 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
};
/*
DECTERM stuff. Probably never need
hide : '?25l',
show : '?25h',*/
//
// Select Graphics Rendition
// 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 cprListener = function(pos) {
console.log(pos)
if(mciPosQueue.length > 0) {
var forMapItem = mciPosQueue.shift();
mciMap[forMapItem].position = pos;
@ -437,6 +438,7 @@ function display(options, cb) {
};
function completed() {
console.log('completed')
options.client.removeListener('cursor position report', cprListener);
parser.removeAllListeners(); // :TODO: Necessary???
@ -507,7 +509,8 @@ function display(options, cb) {
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) {
options.client.term.write(ansiFont);
options.client.term.rawWrite(ansiFont);
}
if(iceColors) {
options.client.term.write(ansi.blinkToBrightIntensity());
options.client.term.rawWrite(ansi.blinkToBrightIntensity());
}
parser.reset(options.art);

View File

@ -107,10 +107,28 @@ 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(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');
exports.pipeToAnsi = exports.renegadeToAnsi = renegadeToAnsi;
exports.stripPipeCodes = exports.stripRenegadeCodes = stripRenegadeCodes;
exports.pipeToAnsi = exports.enigmaToAnsi = enigmaToAnsi;
exports.stripPipeCodes = exports.stripEnigmaCodes = stripEnigmaCodes;
// :TODO: Not really happy with the module name of "color_codes". Would like something better
@ -19,7 +19,7 @@ exports.stripPipeCodes = exports.stripRenegadeCodes = stripRenegadeCodes;
// * fromWWIV(): <ctrl-c><0-7>
// * fromSyncronet(): <ctrl-a><colorCode>
// See http://wiki.synchro.net/custom:colors
function renegadeToAnsi(s) {
function enigmaToAnsi(s) {
if(-1 == s.indexOf('|')) {
return s; // no pipe codes present
}
@ -42,7 +42,7 @@ function renegadeToAnsi(s) {
val = 0;
}
assert(val >= 0 && val <= 256); // :TODO: should be <= 23 I believe
assert(val >= 0 && val <= 47);
var attr = '';
if(7 == val) {
@ -62,7 +62,51 @@ function renegadeToAnsi(s) {
return result;
}
function stripRenegadeCodes(s) {
// :TODO: NYI
function renegadeToAnsi(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 <= 23);
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;
}
function stripEnigmaCodes(s) {
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 theme = require('./theme.js');
var moduleUtil = require('./module_util.js');
//var Log = require('./logger.js').log;
var Config = require('./config.js').config;

View File

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

View File

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

View File

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

View File

@ -163,4 +163,4 @@ function displayThemeArt(options, cb) {
});
}
});
}
}

View File

@ -54,13 +54,12 @@ function VerticalMenuView(options) {
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);
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() {
self.client.term.write(ansi.hideCursor());
self.client.term.rawWrite(ansi.hideCursor());
};
this.restoreCursor = function() {
//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) {
this.client.term.write(ansi.hideCursor());
this.client.term.rawWrite(ansi.hideCursor());
for(var id in this.views) {
if(initialFocusId === id) {
@ -314,7 +314,7 @@ ViewController.prototype.redrawAll = function(initialFocusId) {
this.views[id].redraw();
}
this.client.term.write(ansi.showCursor());
this.client.term.rawWrite(ansi.showCursor());
};
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 ViewController = require('../core/view_controller.js').ViewController;
var ansi = require('../core/ansi_term.js');
var async = require('async');
var assert = require('assert');
@ -25,30 +26,25 @@ function FullScreenEditorModule(options) {
this.artNames = [ 'header', 'body', 'footerEdit', 'footerEditMenu', 'footerView' ];
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() {
var mciData = { };
var art = self.menuConfig.config.art;
assert(_.isObject(art));
// :TODO: async.series here?
async.waterfall(
async.series(
[
function beforeDisplayArt(callback) {
self.beforeArt();
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) {
assert(_.isString(art.header));
assert(_.isString(art.body));
@ -62,9 +58,27 @@ function FullScreenEditorModule(options) {
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);
},
function displayArtFooter(callback) {
var footerName = self.getFooterName(false);
self.displayArtAsset(art[footerName], function artDisplayed(err, artData) {
mciData[footerName] = artData;
callback(err);
});
},
function afterArtDisplayed(callback) {
self.mciReady(mciData);
callback(null);
@ -88,7 +102,7 @@ function FullScreenEditorModule(options) {
self.addViewController(
'header',
new ViewController( { client : self.client } )
new ViewController( { client : self.client, formId : 0 } )
).loadFromMenuConfig(menuLoadOpts, function headerReady(err) {
callback(err);
});
@ -99,10 +113,23 @@ function FullScreenEditorModule(options) {
self.addViewController(
'body',
new ViewController( { client : self.client } )
new ViewController( { client : self.client, formId : 1 } )
).loadFromMenuConfig(menuLoadOpts, function bodyReady(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) {
@ -112,25 +139,30 @@ function FullScreenEditorModule(options) {
);
};
/*
this.mciReadyHandlerNetMail = function(mciData) {
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.getBodyView = function() {
return self.viewControllers.body.getView(1);
};
*/
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 = {
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.getBodyView().on('cursor position', function cursorPosUpdate(pos) {
self.updateEditModePosition(pos);
});
},
editorEscPressed : function(formData, extraArgs) {

View File

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