@@ -86,19 +86,13 @@ static void display(struct progress *progress, uint64_t n, const char *done)
{
const char *tp;
struct strbuf *counters_sb = &progress->counters_sb;
- int update = 0;
+ int show_update = 0;
int last_count_len = counters_sb->len;
if (progress->delay && (!progress_update || --progress->delay))
return;
progress->last_value = n;
-
- if (!is_foreground_fd(fileno(stderr)) && !done) {
- progress_update = 0;
- return;
- }
-
tp = (progress->throughput) ? progress->throughput->display.buf : "";
if (progress->total) {
unsigned percent = n * 100 / progress->total;
@@ -110,35 +104,39 @@ static void display(struct progress *progress, uint64_t n, const char *done)
"%3u%% (%"PRIuMAX"/%"PRIuMAX")%s", percent,
(uintmax_t)n, (uintmax_t)progress->total,
tp);
- update = 1;
+ show_update = 1;
}
} else if (progress_update) {
strbuf_reset(counters_sb);
strbuf_addf(counters_sb, "%"PRIuMAX"%s", (uintmax_t)n, tp);
- update = 1;
+ show_update = 1;
}
- if (update) {
- const char *eol = done ? done : "\r";
- int clear_len = counters_sb->len < last_count_len ?
- last_count_len - counters_sb->len : 0;
- int cols = term_columns();
-
- if (progress->split) {
- fprintf(stderr, " %s%-*s", counters_sb->buf, clear_len,
- eol);
- } else if (!done &&
- cols < progress->title_len + counters_sb->len + 2) {
- clear_len = progress->title_len + 1 < cols ?
- cols - progress->title_len - 1 : 0;
- fprintf(stderr, "%s:%*s\n %s%s", progress->title,
- clear_len, "", counters_sb->buf, eol);
- progress->split = 1;
- } else {
- fprintf(stderr, "%s: %s%-*s", progress->title,
- counters_sb->buf, clear_len, eol);
+ if (show_update) {
+ if (is_foreground_fd(fileno(stderr)) || done) {
+ const char *eol = done ? done : "\r";
+ int clear_len = counters_sb->len < last_count_len ?
+ last_count_len - counters_sb->len : 0;
+ int progress_line_len = progress->title_len +
+ counters_sb->len + 2;
+ int cols = term_columns();
+
+ if (progress->split) {
+ fprintf(stderr, " %s%-*s", counters_sb->buf,
+ clear_len, eol);
+ } else if (!done && cols < progress_line_len) {
+ clear_len = progress->title_len + 1 < cols ?
+ cols - progress->title_len - 1 : 0;
+ fprintf(stderr, "%s:%*s\n %s%s",
+ progress->title, clear_len, "",
+ counters_sb->buf, eol);
+ progress->split = 1;
+ } else {
+ fprintf(stderr, "%s: %s%-*s", progress->title,
+ counters_sb->buf, clear_len, eol);
+ }
+ fflush(stderr);
}
- fflush(stderr);
progress_update = 0;
}
@@ -242,7 +240,7 @@ static struct progress *start_progress_delay(const char *title, uint64_t total,
progress->throughput = NULL;
progress->start_ns = getnanotime();
strbuf_init(&progress->counters_sb, 0);
- progress->title_len = strlen(title);
+ progress->title_len = utf8_strwidth(title);
progress->split = 0;
set_progress_signal();
return progress;