Fixed changes from code review
This commit is contained in:
parent
4aed3c059d
commit
abaca6c8ef
|
@ -24,7 +24,7 @@ function ANSIEscapeParser(options) {
|
||||||
this.scrollBack = 0;
|
this.scrollBack = 0;
|
||||||
this.graphicRendition = {};
|
this.graphicRendition = {};
|
||||||
|
|
||||||
if(options.startRow != null) {
|
if(!_.isNil(options.startRow)) {
|
||||||
this.row = options.startRow;
|
this.row = options.startRow;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -23,6 +23,12 @@ module.exports = () => {
|
||||||
// during the connect process, but provides better autoconfiguration of utf-8
|
// during the connect process, but provides better autoconfiguration of utf-8
|
||||||
checkUtf8Encoding : true,
|
checkUtf8Encoding : true,
|
||||||
|
|
||||||
|
// Checking the ANSI home position also requires the use of cursor position reports, which are not
|
||||||
|
// supported on all terminals. Using this with a terminal that does not support cursor position reports
|
||||||
|
// results in a 3 second delay during the connect process, but works around positioning problems with
|
||||||
|
// non-standard terminals.
|
||||||
|
checkAnsiHomePosition: true,
|
||||||
|
|
||||||
// List of terms that should be assumed to use cp437 encoding
|
// List of terms that should be assumed to use cp437 encoding
|
||||||
cp437TermList : ['ansi', 'pcansi', 'pc-ansi', 'ansi-bbs', 'qansi', 'scoansi', 'syncterm', 'ansi-256color', 'ansi-256color-rgb'],
|
cp437TermList : ['ansi', 'pcansi', 'pc-ansi', 'ansi-bbs', 'qansi', 'scoansi', 'syncterm', 'ansi-256color', 'ansi-256color-rgb'],
|
||||||
// List of terms that should be assumed to use utf8 encoding
|
// List of terms that should be assumed to use utf8 encoding
|
||||||
|
|
|
@ -12,6 +12,58 @@ const async = require('async');
|
||||||
|
|
||||||
exports.connectEntry = connectEntry;
|
exports.connectEntry = connectEntry;
|
||||||
|
|
||||||
|
function ansiDiscoverHomePosition(client, cb) {
|
||||||
|
//
|
||||||
|
// We want to find the home position. ANSI-BBS and most terminals
|
||||||
|
// utilize 1,1 as home. However, some terminals such as ConnectBot
|
||||||
|
// think of home as 0,0. If this is the case, we need to offset
|
||||||
|
// our positioning to accommodate for such.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
if( !Config().term.checkAnsiHomePosition ) {
|
||||||
|
// Skip (and assume 1,1) if the home position check is disabled.
|
||||||
|
return cb(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
const done = (err) => {
|
||||||
|
client.removeListener('cursor position report', cprListener);
|
||||||
|
clearTimeout(giveUpTimer);
|
||||||
|
return cb(err);
|
||||||
|
};
|
||||||
|
|
||||||
|
const cprListener = function(pos) {
|
||||||
|
const h = pos[0];
|
||||||
|
const w = pos[1];
|
||||||
|
|
||||||
|
//
|
||||||
|
// We expect either 0,0, or 1,1. Anything else will be filed as bad data
|
||||||
|
//
|
||||||
|
if(h > 1 || w > 1) {
|
||||||
|
client.log.warn( { height : h, width : w }, 'Ignoring ANSI home position CPR due to unexpected values');
|
||||||
|
return done(Errors.UnexpectedState('Home position CPR expected to be 0,0, or 1,1'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(0 === h & 0 === w) {
|
||||||
|
//
|
||||||
|
// Store a CPR offset in the client. All CPR's from this point on will offset by this amount
|
||||||
|
//
|
||||||
|
client.log.info('Setting CPR offset to 1');
|
||||||
|
client.cprOffset = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return done(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
client.once('cursor position report', cprListener);
|
||||||
|
|
||||||
|
const giveUpTimer = setTimeout( () => {
|
||||||
|
return done(Errors.General('Giving up on home position CPR'));
|
||||||
|
}, 3000); // 3s
|
||||||
|
|
||||||
|
client.term.write(`${ansi.goHome()}${ansi.queryPos()}`); // go home, query pos
|
||||||
|
}
|
||||||
|
|
||||||
function ansiAttemptDetectUTF8(client, cb) {
|
function ansiAttemptDetectUTF8(client, cb) {
|
||||||
//
|
//
|
||||||
// Trick to attempt and detect UTF-8. While there is a lot more than
|
// Trick to attempt and detect UTF-8. While there is a lot more than
|
||||||
|
@ -173,6 +225,11 @@ function connectEntry(client, nextMenu) {
|
||||||
term.rawWrite(ansi.queryDeviceAttributes(0));
|
term.rawWrite(ansi.queryDeviceAttributes(0));
|
||||||
return callback(null);
|
return callback(null);
|
||||||
},
|
},
|
||||||
|
function discoverHomePosition(callback) {
|
||||||
|
ansiDiscoverHomePosition(client, () => {
|
||||||
|
return callback(null); // we try to continue anyway
|
||||||
|
});
|
||||||
|
},
|
||||||
function queryTermSizeByNonStandardAnsi(callback) {
|
function queryTermSizeByNonStandardAnsi(callback) {
|
||||||
ansiQueryTermSizeIfNeeded(client, err => {
|
ansiQueryTermSizeIfNeeded(client, err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
|
|
@ -105,7 +105,7 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
||||||
|
|
||||||
const options = self.menuConfig.config;
|
const options = self.menuConfig.config;
|
||||||
|
|
||||||
if(artData != null && artData.height != null) {
|
if(!_.isNil(artData) && _.isNumber(artData.height)) {
|
||||||
options.startRow = artData.height + 1;
|
options.startRow = artData.height + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
||||||
},
|
},
|
||||||
function displayPauseIfRequested(callback) {
|
function displayPauseIfRequested(callback) {
|
||||||
if(!self.shouldPause()) {
|
if(!self.shouldPause()) {
|
||||||
return callback(null);
|
return callback(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self.client.term.termHeight > 0 && pausePosition.row > self.client.termHeight) {
|
if(self.client.term.termHeight > 0 && pausePosition.row > self.client.termHeight) {
|
||||||
|
|
Loading…
Reference in New Issue