Repository navigation
progress: trim to the terminal width when writing to stderr - #449
Open
stepancheg wants to merge 1 commit into
Open
stepancheg wants to merge 1 commit into
stepancheg wants to merge 1 commit into
Conversation
This commit was generated by AI. The size watcher ran only for `os.Stdout` and always measured stdout, so a bar written to stderr kept a width of 0 and was never trimmed. In a narrow terminal the line wrapped, and because the redraw moves the cursor up one row per tracker, every refresh left the old line behind and the output scrolled. For example, the img tool in [rules_img](https://github.com/bazel-contrib/rules_img) writes its bars to `os.Stderr`, and they overflow terminals narrower than about 110 columns. Measure the file descriptor of the output writer when it is a terminal (`os.Stdout`, `os.Stderr` or another file). Buffers and wrappers that do not expose `Fd()` behave as before, and `SetTerminalWidth` still overrides the measured width. Bars written to stderr are now cut at the terminal width, as stdout bars already were, so long messages may be truncated where they used to wrap. Calling `Fd()` puts an `*os.File` into blocking mode; the old code already did this to `os.Stdout`, and now it also happens to other file writers. The pseudo-terminal tests use ioctls from `golang.org/x/sys`, already a dependency, rather than adding a pty library just for tests. Opening a pty that way differs on each OS, so the tests are Linux-only, which is what CI runs. Windows is untested beyond compiling.
|
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.



This commit was generated by AI.
The size watcher ran only for
os.Stdoutand always measured stdout, so a bar written to stderr kept a width of 0 and was never trimmed. In a narrow terminal the line wrapped, and because the redraw moves the cursor up one row per tracker, every refresh left the old line behind and the output scrolled. For example, the img tool in rules_img writes its bars toos.Stderr, and they overflow terminals narrower than about 110 columns.Measure the file descriptor of the output writer when it is a terminal (
os.Stdout,os.Stderror another file). Buffers and wrappers that do not exposeFd()behave as before, andSetTerminalWidthstill overrides the measured width.Bars written to stderr are now cut at the terminal width, as stdout bars already were, so long messages may be truncated where they used to wrap. Calling
Fd()puts an*os.Fileinto blocking mode; the old code already did this toos.Stdout, and now it also happens to other file writers.The pseudo-terminal tests use ioctls from
golang.org/x/sys, already a dependency, rather than adding a pty library just for tests. Opening a pty that way differs on each OS, so the tests are Linux-only, which is what CI runs. Windows is untested beyond compiling.