Skip to content

Commit

Permalink
Fix error when no TERM environment variable (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
styfle and sindresorhus committed Dec 18, 2019
1 parent 92aa07e commit 07b96f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
16 changes: 9 additions & 7 deletions index.js
Expand Up @@ -56,14 +56,16 @@ module.exports = () => {
}
} catch (_) {}

try {
const columns = exec('tput', ['cols']);
const rows = exec('tput', ['lines']);
if (process.env.TERM) {
try {
const columns = exec('tput', ['cols']);
const rows = exec('tput', ['lines']);

if (columns && rows) {
return create(columns, rows);
}
} catch (_) {}
if (columns && rows) {
return create(columns, rows);
}
} catch (_) {}
}
}

return create(80, 24);
Expand Down
11 changes: 11 additions & 0 deletions test.js
Expand Up @@ -15,3 +15,14 @@ test('child', async t => {
t.true(parseInt(columns, 10) > 0);
t.true(parseInt(rows, 10) > 0);
});

test('no TERM environment variable', t => {
const envTerm = process.env.TERM;
process.env.TERM = undefined;
const size = termSize();
process.env.TERM = envTerm;

console.log('Size with no $TERM:', size);
t.true(size.columns > 0);
t.true(size.rows > 0);
});

0 comments on commit 07b96f0

Please sign in to comment.