read $COLUMNS before defaulting width 80 when no tty #737
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 patch attempts to let the user override the "not/unknown terminal" width using a standard environment variable. When stdin is not a tty, we'll default to
$COLUMNS, rather than the hardcoded 80, ifatoi()works on the value. If not sane or not present, defaults to 80 columns as before. This is likely to work correctly in most scenarios and not change existing behavior, because$COLUMNSwould usually only be set for a terminal, and the termios determination will override the environment there.Use case: a keybind for
timew summary :dayin window manager to display in a transient window. Bound action executes in a fork of the wm, which doesn't have a tty, and its stdin/out/err are/dev/null. After the recent #566, the summary output is now always 80 columns therein. So this patch gives a workaround and should have good behavior for everyone.Please apply, thanks.