make progress "title" part of the common progress interface

If the progress bar ends up in a box, better provide a title for it too.

Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Nicolas Pitre
2007-04-20 14:10:07 -04:00
committed by Junio C Hamano
parent 96a02f8f6d
commit 13aaf14825
6 changed files with 27 additions and 34 deletions

View File

@ -40,23 +40,27 @@ int display_progress(struct progress *progress, unsigned n)
if (percent != progress->last_percent || progress_update) {
progress->last_percent = percent;
fprintf(stderr, "%s%4u%% (%u/%u) done\r",
progress->msg, percent, n, progress->total);
progress->prefix, percent, n, progress->total);
progress_update = 0;
return 1;
}
} else if (progress_update) {
fprintf(stderr, "%s%u\r", progress->msg, n);
fprintf(stderr, "%s%u\r", progress->prefix, n);
progress_update = 0;
return 1;
}
return 0;
}
void start_progress(struct progress *progress, const char *msg, unsigned total)
void start_progress(struct progress *progress, const char *title,
const char *prefix, unsigned total)
{
progress->msg = msg;
char buf[80];
progress->prefix = prefix;
progress->total = total;
progress->last_percent = -1;
if (snprintf(buf, sizeof(buf), title, total))
fprintf(stderr, "%s\n", buf);
set_progress_signal();
}