Use terminal-size as fallback for piped processes#854
Merged
sindresorhus merged 1 commit intoJan 21, 2026
Conversation
When stdout is piped (e.g., `node app.js | cat`), `stdout.columns` is 0 or undefined. This change uses the terminal-size package to detect the actual terminal width as a fallback before defaulting to 80 columns. Changes: - Add terminal-size package as dependency - Modify getTerminalWidth() to use terminal-size when stdout.columns is unavailable - Update screen reader code path to use getTerminalWidth() for consistency Fixes #670
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
terminal-sizepackage to detect actual terminal width whenstdout.columnsis unavailable (piped processes)Problem
When Ink's output is piped (e.g.,
node app.js | cat),stdout.columnsreturns0orundefined, causing layout to default to 80 columns even when the terminal is wider.Solution
The
terminal-sizepackage can detect terminal dimensions even when stdout is piped, by checking stdin/stderr or using platform-specific methods.Changes made:
terminal-sizedependency - Zero-dependency package by @sindresorhusgetTerminalWidth()method - Uses terminal-size as fallback:stdout.columnsaccess to usegetTerminalWidth()for consistencyTest plan
stdout.columnsusages now go throughgetTerminalWidth()npm run example test.tsx | cat) detects actual terminal width instead of defaulting to 80Fixes #670