ToggleMenuView causes Engima to crash when connecting with ConnectBot #83

This commit is contained in:
Bryan Ashby 2016-08-13 10:05:49 -06:00
parent 383b3b449d
commit cf30389146
1 changed files with 35 additions and 31 deletions

View File

@ -1,36 +1,36 @@
/* jslint node: true */ /* jslint node: true */
'use strict'; 'use strict';
var ansi = require('./ansi_term.js'); // ENiGMA½
const ansi = require('./ansi_term.js');
var assert = require('assert');
exports.connectEntry = connectEntry; exports.connectEntry = connectEntry;
function ansiQueryTermSizeIfNeeded(client, cb) { function ansiQueryTermSizeIfNeeded(client, cb) {
if(client.term.termHeight > 0 || client.term.termWidth > 0) { if(client.term.termHeight > 0 || client.term.termWidth > 0) {
cb(true); return cb(null);
return;
} }
var done = function(res) { const done = function(err) {
client.removeListener('cursor position report', cprListener); client.removeListener('cursor position report', cprListener);
clearTimeout(giveUpTimer); clearTimeout(giveUpTimer);
cb(res); return cb(err);
}; };
var cprListener = function(pos) { const cprListener = function(pos) {
// //
// If we've already found out, disregard // If we've already found out, disregard
// //
if(client.term.termHeight > 0 || client.term.termWidth > 0) { if(client.term.termHeight > 0 || client.term.termWidth > 0) {
done(true); return done(null);
return;
} }
assert(2 === pos.length); if(2 !== pos.length) {
var h = pos[0]; client.log.warn( { cprPosition : pos }, 'Unexpected CPR format');
var w = pos[1]; }
const h = pos[0] || 0;
const w = pos[1] || 0;
// //
// Netrunner for example gives us 1x1 here. Not really useful. Ignore // Netrunner for example gives us 1x1 here. Not really useful. Ignore
@ -40,8 +40,7 @@ function ansiQueryTermSizeIfNeeded(client, cb) {
client.log.warn( client.log.warn(
{ height : h, width : w }, { height : h, width : w },
'Ignoring ANSI CPR screen size query response due to very small values'); 'Ignoring ANSI CPR screen size query response due to very small values');
done(false); return done(new Error('Term size <= 10 considered invalid'));
return;
} }
client.term.termHeight = h; client.term.termHeight = h;
@ -56,17 +55,17 @@ function ansiQueryTermSizeIfNeeded(client, cb) {
'Window size updated' 'Window size updated'
); );
done(true); return done(null);
}; };
client.once('cursor position report', cprListener); client.once('cursor position report', cprListener);
// give up after 2s // give up after 2s
var giveUpTimer = setTimeout(function onTimeout() { const giveUpTimer = setTimeout( () => {
done(false); return done(new Error('No term size established by CPR within timeout'));
}, 2000); }, 2000);
// This causes // Start the process: Query for CPR
client.term.rawWrite(ansi.queryScreenSize()); client.term.rawWrite(ansi.queryScreenSize());
} }
@ -85,7 +84,7 @@ function displayBanner(term) {
} }
function connectEntry(client, nextMenu) { function connectEntry(client, nextMenu) {
var term = client.term; const term = client.term;
// :TODO: Enthral for example queries cursor position & checks if it worked. This might be good // :TODO: Enthral for example queries cursor position & checks if it worked. This might be good
// :TODO: How to detect e.g. if show/hide cursor can work? Probably can if CPR is avail // :TODO: How to detect e.g. if show/hide cursor can work? Probably can if CPR is avail
@ -101,18 +100,23 @@ function connectEntry(client, nextMenu) {
// If we don't yet know the client term width/height, // If we don't yet know the client term width/height,
// try with a nonstandard ANSI DSR type request. // try with a nonstandard ANSI DSR type request.
// //
ansiQueryTermSizeIfNeeded(client, function ansiCprResult(result) { ansiQueryTermSizeIfNeeded(client, err => {
if(!result) { if(err) {
// //
// We still don't have something good for term height/width. // Check again; We may have got via NAWS/similar before CPR completed.
// Default to DOS size 80x25.
// //
// :TODO: Netrunner is currenting hitting this and it feels wrong. Why is NAWS/ENV/CPR all failing??? if(0 === term.termHeight || 0 === term.termWidth) {
client.log.warn('Failed to negotiate term size; Defaulting to 80x25!'); //
// We still don't have something good for term height/width.
// Default to DOS size 80x25.
//
// :TODO: Netrunner is currenting hitting this and it feels wrong. Why is NAWS/ENV/CPR all failing???
client.log.warn( { reason : err.message }, 'Failed to negotiate term size; Defaulting to 80x25!');
term.termHeight = 25; term.termHeight = 25;
term.termWidth = 80; term.termWidth = 80;
}
} }
prepareTerminal(term); prepareTerminal(term);
@ -122,8 +126,8 @@ function connectEntry(client, nextMenu) {
// //
displayBanner(term); displayBanner(term);
setTimeout(function onTimeout() { setTimeout( () => {
client.menuStack.goto(nextMenu); return client.menuStack.goto(nextMenu);
}, 500); }, 500);
}); });
} }