From 0230d9958c8a2e5e088c710e53c34cf08f48f35b Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 31 Dec 2018 11:30:40 -0700 Subject: [PATCH] Better screen size detection when NAWS/etc. fails: Ask to move cursor to 999,999. We expect that we'll really get something like 80x25 generally. *Then* issue special DSR that should give us screen size. We should get a good "bottom right" aka screen size either way. --- core/connect.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/connect.js b/core/connect.js index 0b83f7f0..b9316a3e 100644 --- a/core/connect.js +++ b/core/connect.js @@ -80,12 +80,13 @@ function ansiQueryTermSizeIfNeeded(client, cb) { // // NetRunner for example gives us 1x1 here. Not really useful. Ignore - // values that seem obviously bad. + // values that seem obviously bad. Included in the set is the explicit + // 999x999 values we asked to move to. // - if(h < 10 || w < 10) { + if(h < 10 || h === 999 || w < 10 || w === 999) { client.log.warn( { 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 non-sane values'); return done(Errors.Invalid('Term size <= 10 considered invalid')); } @@ -111,12 +112,20 @@ function ansiQueryTermSizeIfNeeded(client, cb) { return done(Errors.General('No term size established by CPR within timeout')); }, 2000); - // Start the process: Query for CPR - client.term.rawWrite(ansi.queryScreenSize()); + // Start the process: + // 1 - Ask to goto 999,999 -- a very much "bottom right" (generally 80x25 for example + // is the real size) + // 2 - Query for screen size with bansi.txt style specialized Device Status Report (DSR) + // request. We expect a CPR of: + // a - Terms that support bansi.txt style: Screen size + // b - Terms that do not support bansi.txt style: Since we moved to the bottom right + // we should still be able to determine a screen size. + // + client.term.rawWrite(`${ansi.goto(999, 999)}${ansi.queryScreenSize()}`); } function prepareTerminal(term) { - term.rawWrite(ansi.normal()); + term.rawWrite(`${ansi.normal()}${ansi.clearScreen()}`); } function displayBanner(term) {