From 386ee674522577c5dc449f1415ae5cc263464518 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 17 Dec 2019 17:38:36 -0500 Subject: [PATCH 1/2] Fix tput error when TERM is undefined --- index.js | 16 +++++++++------- test.js | 8 ++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) 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..5311214 100644 --- a/test.js +++ b/test.js @@ -15,3 +15,11 @@ test('child', async t => { t.true(parseInt(columns, 10) > 0); t.true(parseInt(rows, 10) > 0); }); + +test('no TERM env var', t => { + process.env.TERM = undefined; + const size = termSize(); + console.log('no TERM size:', size); + t.true(size.columns > 0); + t.true(size.rows > 0); +}); From 13631ffdd5366d91b1af14a793e382997c5a1fea Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 18 Dec 2019 18:16:42 +0100 Subject: [PATCH 2/2] Update test.js --- test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index 5311214..6fbe049 100644 --- a/test.js +++ b/test.js @@ -16,10 +16,13 @@ test('child', async t => { t.true(parseInt(rows, 10) > 0); }); -test('no TERM env var', t => { +test('no TERM environment variable', t => { + const envTerm = process.env.TERM; process.env.TERM = undefined; const size = termSize(); - console.log('no TERM size:', size); + process.env.TERM = envTerm; + + console.log('Size with no $TERM:', size); t.true(size.columns > 0); t.true(size.rows > 0); });