-
Notifications
You must be signed in to change notification settings - Fork 71
feat: add terminal width support to StringWriteStream
#1028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Head branch was pushed to by a user without write access
d507780 to
69ac99b
Compare
StringWriteStreamStringWriteStream
rix0rrr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Does this mean we need to implement a specific interface that advertises columns? Who gets to take advantage of this?
| constructor() { | ||
| super(); | ||
| // Read terminal width from stdout to enable proper table formatting | ||
| this.columns = process.stdout.columns; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be a getter, because the column count can change over time.
69ac99b to
f59f646
Compare
@rix0rrr Thanks for the quick review! I've added some more information to the Context and Consequences sections in the PR description. |
f59f646 to
b49b40c
Compare
Adds terminal width detection to StringWriteStream to enable proper table formatting that respects terminal width constraints and prevents overflow. The columns getter dynamically reads from process.stdout.columns, allowing it to reflect runtime changes such as terminal resizing. Returns undefined in non-TTY environments (e.g., CI/CD pipelines). Includes comprehensive unit tests with 100% coverage covering: - Core stream functionality (writing, buffering, conversion) - Terminal width initialization and handling - TTY and non-TTY environment support - Multiple terminal width scenarios - Dynamic terminal resize handling
b49b40c to
b343464
Compare
Context
The diff formatting library expects streams to provide an optional
columnsproperty (via theFormatStreaminterface) to enable terminal width-aware table formatting. StringWriteStream currently lacks this property, causing the diff formatter to format tables without width constraints, leading to overflow and poor rendering in different terminal environments.Changes
columnsgetter to StringWriteStream that dynamically reads terminal width fromprocess.stdout.columnsundefinedin non-TTY environments (CI/CD pipelines, redirected output)formatTable()for IAM changes, security group changes, and other table-formatted outputConsequences
The
Formatterclass will automatically use this property when callingformatTable()for IAM changes, security group changes, and other table-formatted outputConsiderations
The
columnsgetter reads fromprocess.stdout.columnson every access, ensuring it always reflects the current terminal width. This design allows the stream to respond to terminal resize events without requiring additional event listeners or manual updates. The diff formatter will automatically pick up this property through the existingFormatStreaminterface.Now, there's no guarantee that people will output the text collected in the
StringWriteStreamto stdout, but that is my use case. 🤷By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license