diff --git a/index.js b/index.js index 4a4e833..09804a4 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/test.js b/test.js index d156332..6fbe049 100644 --- a/test.js +++ b/test.js @@ -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); +});