Skip to content

Commit 5a8fbb6

Browse files
committed
Fix COLUMNS/LINES injection to match TTY allocation logic
The TTY allocation condition checks both stdin.isTTY && stdout.isTTY, but COLUMNS/LINES were only injected when !stdout.isTTY. This caused missing terminal size hints when stdin is not a TTY but stdout is (e.g., piped input). Changed the condition to match the PTY allocation logic: inject COLUMNS/LINES when !(stdin.isTTY && stdout.isTTY). Also updated test helper to include stdin in context and added test coverage for the stdin-not-TTY-but-stdout-is-TTY scenario.
1 parent 568fb81 commit 5a8fbb6

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

test/build-exec-environment.spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const buildEnvironment = require('../utils/build-exec-environment');
1414
// Helper — build a context with a controlled env so tests never
1515
// touch process.env and don't need save/restore boilerplate.
1616
const makeCtx = (overrides = {}) => {
17-
const {env, stdout, stderr, ...rest} = overrides;
17+
const {env, stdin, stdout, stderr, ...rest} = overrides;
1818
return {
19+
stdin: {isTTY: true, ...stdin},
1920
stdout: {isTTY: true, columns: 80, rows: 24, ...stdout},
2021
stderr: {isTTY: true, ...stderr},
2122
env: env || {},
@@ -125,8 +126,15 @@ describe('build-exec-environment', () => {
125126
expect(env.LINES).to.equal('40');
126127
});
127128

128-
it('should not set COLUMNS and LINES when stdout is a TTY', () => {
129-
const ctx = makeCtx({stdout: {isTTY: true, columns: 120, rows: 40}});
129+
it('should set COLUMNS and LINES when stdin is not a TTY but stdout is', () => {
130+
const ctx = makeCtx({stdin: {isTTY: false}, stdout: {isTTY: true, columns: 120, rows: 40}});
131+
const env = buildEnvironment(ctx);
132+
expect(env.COLUMNS).to.equal('120');
133+
expect(env.LINES).to.equal('40');
134+
});
135+
136+
it('should not set COLUMNS and LINES when both stdin and stdout are TTY', () => {
137+
const ctx = makeCtx({stdin: {isTTY: true}, stdout: {isTTY: true, columns: 120, rows: 40}});
130138
const env = buildEnvironment(ctx);
131139
expect(env).to.not.have.property('COLUMNS');
132140
expect(env).to.not.have.property('LINES');

utils/build-exec-environment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = (context, userEnv = {}) => {
3636
synthetic.NO_COLOR = '1';
3737
}
3838

39-
if (!context.stdout.isTTY) {
39+
if (!(context.stdin.isTTY && context.stdout.isTTY)) {
4040
// No PTY means no SIGWINCH, but a static hint is better than nothing
4141
synthetic.COLUMNS = String(context.stdout.columns);
4242
synthetic.LINES = String(context.stdout.rows);

0 commit comments

Comments
 (0)