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.
This commit is contained in:
Bryan Ashby 2018-12-31 11:30:40 -07:00
parent 78484a2352
commit 0230d9958c
1 changed files with 15 additions and 6 deletions

View File

@ -80,12 +80,13 @@ function ansiQueryTermSizeIfNeeded(client, cb) {
// //
// NetRunner for example gives us 1x1 here. Not really useful. Ignore // 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( 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 non-sane values');
return done(Errors.Invalid('Term size <= 10 considered invalid')); 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')); return done(Errors.General('No term size established by CPR within timeout'));
}, 2000); }, 2000);
// Start the process: Query for CPR // Start the process:
client.term.rawWrite(ansi.queryScreenSize()); // 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) { function prepareTerminal(term) {
term.rawWrite(ansi.normal()); term.rawWrite(`${ansi.normal()}${ansi.clearScreen()}`);
} }
function displayBanner(term) { function displayBanner(term) {