mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-23 19:20:41 +02:00
* Some code cleanup
* WIP additional terminal types * Minor updates to deleting lines in multi line edit - much to go still
This commit is contained in:
parent
68f5a4cbfb
commit
dc69428563
3 changed files with 63 additions and 12 deletions
|
@ -6,6 +6,7 @@ var Log = require('./logger.js').log;
|
||||||
|
|
||||||
var iconv = require('iconv-lite');
|
var iconv = require('iconv-lite');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
iconv.extendNodeEncodings();
|
iconv.extendNodeEncodings();
|
||||||
|
|
||||||
|
@ -56,12 +57,25 @@ function ClientTerminal(output) {
|
||||||
//
|
//
|
||||||
// ANSI terminals should be encoded to CP437
|
// ANSI terminals should be encoded to CP437
|
||||||
//
|
//
|
||||||
if('ansi' == termType) {
|
// Some terminal types provided by Mercyful Fate / Enthral:
|
||||||
|
// ANSI-BBS
|
||||||
|
// PC-ANSI
|
||||||
|
// QANSI
|
||||||
|
// SCOANSI
|
||||||
|
// VT100
|
||||||
|
// XTERM
|
||||||
|
// LINUX
|
||||||
|
// QNX
|
||||||
|
// SCREEN
|
||||||
|
//
|
||||||
|
if(this.isANSI()) {
|
||||||
this.outputEncoding = 'cp437';
|
this.outputEncoding = 'cp437';
|
||||||
} else {
|
} else {
|
||||||
// :TODO: See how x84 does this -- only set if local/remote are binary
|
// :TODO: See how x84 does this -- only set if local/remote are binary
|
||||||
this.outputEncoding = 'utf8';
|
this.outputEncoding = 'utf8';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.debug( { encoding : this.outputEncoding }, 'Set output encoding due to terminal type change');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -89,12 +103,13 @@ function ClientTerminal(output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientTerminal.prototype.isANSI = function() {
|
ClientTerminal.prototype.isANSI = function() {
|
||||||
return 'ansi' === this.termType;
|
// :TODO: Others??
|
||||||
|
return [ 'ansi', 'pc-ansi', 'qansi', 'scoansi' ].indexOf(this.termType) > -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientTerminal.prototype.write = function(s, convertLineFeeds) {
|
ClientTerminal.prototype.write = function(s, convertLineFeeds) {
|
||||||
convertLineFeeds = typeof convertLineFeeds === 'undefined' ? this.convertLF : convertLineFeeds;
|
convertLineFeeds = _.isUndefined(convertLineFeeds) ? this.convertLF : convertLineFeeds;
|
||||||
if(convertLineFeeds && typeof s === 'string') {
|
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(iconv.encode(s, this.outputEncoding));
|
||||||
|
|
|
@ -146,11 +146,42 @@ function MultiLineEditTextView2(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.client.term.write(ansi.showCursor());
|
self.client.term.write(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());
|
||||||
|
|
||||||
|
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.showCursor());
|
||||||
};
|
};
|
||||||
|
|
||||||
this.redrawVisibleArea = function() {
|
this.redrawVisibleArea = function() {
|
||||||
assert(self.topVisibleIndex <= self.textLines.length);
|
assert(self.topVisibleIndex <= self.textLines.length);
|
||||||
self.redrawRows(0, self.dimens.height);
|
var lastRow = self.redrawRows(0, self.dimens.height);
|
||||||
|
|
||||||
|
self.eraseRows(lastRow, self.dimens.height);
|
||||||
|
/*
|
||||||
|
|
||||||
|
// :TOOD: create eraseRows(startRow, endRow)
|
||||||
|
if(lastRow < self.dimens.height) {
|
||||||
|
var absPos = self.getAbsolutePosition(lastRow, 0);
|
||||||
|
var empty = new Array(self.dimens.width).join(' ');
|
||||||
|
while(lastRow++ < self.dimens.height) {
|
||||||
|
self.client.term.write(ansi.goto(absPos.row++, absPos.col));
|
||||||
|
self.client.term.write(empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getVisibleText = function(index) {
|
this.getVisibleText = function(index) {
|
||||||
|
@ -164,7 +195,7 @@ function MultiLineEditTextView2(options) {
|
||||||
if(!_.isNumber(index)) {
|
if(!_.isNumber(index)) {
|
||||||
index = self.getTextLinesIndex();
|
index = self.getTextLinesIndex();
|
||||||
}
|
}
|
||||||
return self.textLines.length > index ? self.textLines[index].text : ''
|
return self.textLines.length > index ? self.textLines[index].text : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getCharacter = function(index, col) {
|
this.getCharacter = function(index, col) {
|
||||||
|
@ -322,8 +353,10 @@ function MultiLineEditTextView2(options) {
|
||||||
var remove = (endIndex - startIndex) + 1;
|
var remove = (endIndex - startIndex) + 1;
|
||||||
console.log('remove=' + remove)
|
console.log('remove=' + remove)
|
||||||
|
|
||||||
|
console.log('lenBefore=' + self.textLines.length)
|
||||||
self.textLines.splice(startIndex, remove);
|
self.textLines.splice(startIndex, remove);
|
||||||
console.log(self.textLines)
|
console.log(self.textLines)
|
||||||
|
console.log('lenAfter=' + self.textLines.length)
|
||||||
|
|
||||||
self.cursorPos.col = 0;
|
self.cursorPos.col = 0;
|
||||||
|
|
||||||
|
@ -336,6 +369,7 @@ function MultiLineEditTextView2(options) {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
self.cursorPos.row -= (index - startIndex);
|
self.cursorPos.row -= (index - startIndex);
|
||||||
|
console.log('self.cursorPos.row=' + self.cursorPos.row)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.redrawVisibleArea();
|
self.redrawVisibleArea();
|
||||||
|
@ -979,7 +1013,7 @@ MultiLineEditTextView2.prototype.setFocus = function(focused) {
|
||||||
MultiLineEditTextView2.prototype.setText = function(text) {
|
MultiLineEditTextView2.prototype.setText = function(text) {
|
||||||
this.textLines = [ ];
|
this.textLines = [ ];
|
||||||
//text = "Tab:\r\n\tA\tB\tC\tD\tE\tF\tG\r\n reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally long word!!!";
|
//text = "Tab:\r\n\tA\tB\tC\tD\tE\tF\tG\r\n reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally long word!!!";
|
||||||
text = require('fs').readFileSync('/home/bashby/Downloads/test_text.txt', { encoding : 'utf-8'});
|
text = require('fs').readFileSync('/home/nuskooler/Downloads/test_text.txt', { encoding : 'utf-8'});
|
||||||
|
|
||||||
this.insertRawText(text);//, 0, 0);
|
this.insertRawText(text);//, 0, 0);
|
||||||
this.cursorEndOfDocument();
|
this.cursorEndOfDocument();
|
||||||
|
|
|
@ -143,7 +143,7 @@ var OPTIONS = {
|
||||||
//PRAGMA_HEARTBEAT : 140
|
//PRAGMA_HEARTBEAT : 140
|
||||||
|
|
||||||
EXTENDED_OPTIONS_LIST : 255, // RFC 861 (STD 32)
|
EXTENDED_OPTIONS_LIST : 255, // RFC 861 (STD 32)
|
||||||
}
|
};
|
||||||
|
|
||||||
// Commands used within NEW_ENVIRONMENT[_DEP]
|
// Commands used within NEW_ENVIRONMENT[_DEP]
|
||||||
var NEW_ENVIRONMENT_COMMANDS = {
|
var NEW_ENVIRONMENT_COMMANDS = {
|
||||||
|
@ -171,7 +171,7 @@ var COMMAND_IMPLS = {};
|
||||||
return MORE_DATA_REQUIRED;
|
return MORE_DATA_REQUIRED;
|
||||||
}
|
}
|
||||||
return parseOption(bufs, i, event);
|
return parseOption(bufs, i, event);
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// :TODO: See TooTallNate's telnet.js: Handle COMMAND_IMPL for IAC in binary mode
|
// :TODO: See TooTallNate's telnet.js: Handle COMMAND_IMPL for IAC in binary mode
|
||||||
|
@ -342,7 +342,9 @@ OPTION_IMPLS[OPTIONS.NEW_ENVIRONMENT] = function(bufs, i, event) {
|
||||||
// :TODO: Currently not supporting ESCaped values (ESC + <type>). Probably not really in the wild, but we should be compliant
|
// :TODO: Currently not supporting ESCaped values (ESC + <type>). Probably not really in the wild, but we should be compliant
|
||||||
var params = [];
|
var params = [];
|
||||||
var p = 0;
|
var p = 0;
|
||||||
for(var j = 0, l = buf.length; j < l; ++j) {
|
var j;
|
||||||
|
var l;
|
||||||
|
for(j = 0, l = buf.length; j < l; ++j) {
|
||||||
if(NEW_ENVIRONMENT_DELIMITERS.indexOf(buf[j]) === -1) {
|
if(NEW_ENVIRONMENT_DELIMITERS.indexOf(buf[j]) === -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -359,7 +361,7 @@ OPTION_IMPLS[OPTIONS.NEW_ENVIRONMENT] = function(bufs, i, event) {
|
||||||
var varName;
|
var varName;
|
||||||
event.envVars = {};
|
event.envVars = {};
|
||||||
// :TODO: handle cases where a variable was present in a previous exchange, but missing here...e.g removed
|
// :TODO: handle cases where a variable was present in a previous exchange, but missing here...e.g removed
|
||||||
for(var j = 0; j < params.length; ++j) {
|
for(j = 0; j < params.length; ++j) {
|
||||||
if(params[j].length < 2) {
|
if(params[j].length < 2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -383,7 +385,7 @@ var MORE_DATA_REQUIRED = 0xfeedface;
|
||||||
|
|
||||||
function parseBufs(bufs) {
|
function parseBufs(bufs) {
|
||||||
assert(bufs.length >= 2);
|
assert(bufs.length >= 2);
|
||||||
assert(bufs.get(0) === COMMANDS.IAC)
|
assert(bufs.get(0) === COMMANDS.IAC);
|
||||||
return parseCommand(bufs, 1, {});
|
return parseCommand(bufs, 1, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue