* 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:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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, '');
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -117,6 +117,7 @@ function MenuModule(options) {
|
||||
],
|
||||
function complete(err) {
|
||||
if(err) {
|
||||
console.log(err)
|
||||
// :TODO: what to do exactly?????
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -81,7 +81,7 @@ function TextView(options) {
|
||||
this.justify,
|
||||
this.hasFocus ? this.getFocusSGR() : this.getSGR(),
|
||||
this.getStyleSGR(1) || this.getSGR()
|
||||
));
|
||||
), false);
|
||||
};
|
||||
|
||||
this.getEndOfTextColumn = function() {
|
||||
|
||||
@@ -163,4 +163,4 @@ function displayThemeArt(options, cb) {
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user