Skip to content

Fix terminal size detection when output is piped#129

Merged
rongxin-liu merged 2 commits intomainfrom
rongxin-patch-1
Mar 17, 2026
Merged

Fix terminal size detection when output is piped#129
rongxin-liu merged 2 commits intomainfrom
rongxin-patch-1

Conversation

@rongxin-liu
Copy link
Copy Markdown
Contributor

@rongxin-liu rongxin-liu commented Mar 17, 2026

This pull request updates the style50 project by simplifying how terminal size is determined and updating the package version. The main change is the replacement of a custom function for detecting terminal size with Python's built-in shutil.get_terminal_size, which reduces code complexity and removes the need for several imports.

Terminal size detection simplification:

  • Replaced the custom get_terminal_size function (which used fcntl, termios, and struct) with a direct call to shutil.get_terminal_size, simplifying the logic for determining terminal dimensions.
  • Removed unused imports: fcntl, struct, and termios are no longer needed due to the simplification above.

Project metadata update:

  • Updated the package version from 2.10.4 to 2.11.0 in setup.py to reflect the new changes.

Closes #127

Copilot AI review requested due to automatic review settings March 17, 2026 13:09
@rongxin-liu rongxin-liu self-assigned this Mar 17, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR simplifies terminal size detection so that when style50 output is piped (i.e., not connected to a TTY), diff formatting falls back to a fixed size rather than attempting to probe other streams.

Changes:

  • Replace custom ioctl-based terminal sizing with shutil.get_terminal_size(fallback=(80, 24)).
  • Remove low-level POSIX-specific imports used by the previous implementation.
  • Bump package version to 2.11.0.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
style50/_api.py Switches terminal-size detection to shutil.get_terminal_size with a fallback for non-TTY output (e.g., piped output).
setup.py Updates package version to reflect the change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rongxin-liu rongxin-liu merged commit d305b0a into main Mar 17, 2026
6 checks passed
@rongxin-liu rongxin-liu deleted the rongxin-patch-1 branch March 17, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

internal get_terminal_size() results in buffer overflow

3 participants