Skip to content

Fall back to verbose mode when terminal width can not be safely obtained - #513

Merged
nxpfrankli merged 5 commits into
nxp-imx:masterfrom
tsundre:fallback-verbose-mode
Sep 25, 2026
Merged

nxpfrankli merged 5 commits into
nxp-imx:masterfrom
tsundre:fallback-verbose-mode

Conversation

@tsundre

@tsundre tsundre commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

46d798b fixed an issue where an indeterminate terminal width ended up with a very large width being used, causing a lot of extra spaces in the output.

46d798b solves this by falling back to a width of 300. This helps, but using a default width is perhaps not likely to produce the best result.

In this PR, I have added a series of commits that causes uuu to fall back to verbose mode in several cases where it does not make sense to output the progress bar.

Note that the Windows change is not tested, since I don't have access to such antiquated technology.

get_console_width() is used to get the console width for calculations
related to output, like the progress bar, but get_console_width()
currently inquires fd 0 (stdin). If stdin is redirected, the returned
width will not be correct.

Inquire stdout instead of stdin, to get the correct output width.

Signed-off-by: Torleiv Sundre <torleiv@huddly.com>
print_oneline() unconditionally converts the returned int from
get_console_width() to a size_t, without verifying that the returned
value is non-negative.

Store the returned width in an int, which will prevent calculation of
nonsensical process bar widths, as was the case before "46d798b Fix
garbage value of console width when no pty".

Change the type of the min() with the string length to int, which should
be safe for any reasonable string size.

Signed-off-by: Torleiv Sundre <torleiv@huddly.com>
Fall back to the verbose mode (no progress bar) if stdout is not a TTY,
for example when piped to another process.

Signed-off-by: Torleiv Sundre <torleiv@huddly.com>
"46d798b Fix garbage value of terminal width when no pty" fixed an issue,
where a failure to obtain the terminal width falls back to a fallback
width of 300 characters.

uuu already has a verbose mode, that is more suitable in situations
where the terminal width can not be found. Fall back to this mode,
instead of setting a fixed width, in all cases where the terminal width
can not be found.

Also fall back to verbose mode if the terminal width is very small. For
now, set the limit to 3, which matches the cutoff used in
print_oneline().

Signed-off-by: Torleiv Sundre <torleiv@huddly.com>
Don't trust the returned buffer info when GetConsoleScreenBufferInfo
fails.

Return -1 on failure, matching the non-WIN32 implementation of
get_console_width().

Signed-off-by: Torleiv Sundre <torleiv@huddly.com>
@nxpfrankli
nxpfrankli merged commit 0220e96 into nxp-imx:master Sep 25, 2026
12 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants