summaryrefslogtreecommitdiff
path: root/progress.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2007-10-16 21:55:45 -0400
committerShawn O. Pearce <spearce@spearce.org>2007-10-17 02:54:55 -0400
commit42e18fbf5f94dd6bd303bf702e030a29fa39d6c4 (patch)
tree5ecf0327f3b5a99e0fc37709aef674d56d825638 /progress.c
parent207f1a75e7e4d14286aeed107af7c56dc811797b (diff)
downloadgit-42e18fbf5f94dd6bd303bf702e030a29fa39d6c4.tar.gz
more compact progress display
Each progress can be on a single line instead of two. [sp: Changed "Checking files out" to "Checking out files" at Johannes Sixt's suggestion as it better explains the action that is taking place] Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'progress.c')
-rw-r--r--progress.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/progress.c b/progress.c
index 4344f4eed5..7629e0572b 100644
--- a/progress.c
+++ b/progress.c
@@ -35,10 +35,11 @@ static void clear_progress_signal(void)
progress_update = 0;
}
-int display_progress(struct progress *progress, unsigned n)
+static int display(struct progress *progress, unsigned n, int done)
{
+ char *eol;
+
if (progress->delay) {
- char buf[80];
if (!progress_update || --progress->delay)
return 0;
if (progress->total) {
@@ -51,60 +52,56 @@ int display_progress(struct progress *progress, unsigned n)
return 0;
}
}
- if (snprintf(buf, sizeof(buf),
- progress->delayed_title, progress->total))
- fprintf(stderr, "%s\n", buf);
}
+
+ progress->last_value = n;
+ eol = done ? ", done. \n" : " \r";
if (progress->total) {
unsigned percent = n * 100 / progress->total;
if (percent != progress->last_percent || progress_update) {
progress->last_percent = percent;
- fprintf(stderr, "%s%4u%% (%u/%u) done\r",
- progress->prefix, percent, n, progress->total);
+ fprintf(stderr, "%s: %3u%% (%u/%u)%s", progress->title,
+ percent, n, progress->total, eol);
progress_update = 0;
- progress->need_lf = 1;
return 1;
}
} else if (progress_update) {
- fprintf(stderr, "%s%u\r", progress->prefix, n);
+ fprintf(stderr, "%s: %u%s", progress->title, n, eol);
progress_update = 0;
- progress->need_lf = 1;
return 1;
}
+
return 0;
}
-void start_progress(struct progress *progress, const char *title,
- const char *prefix, unsigned total)
+int display_progress(struct progress *progress, unsigned n)
{
- char buf[80];
- progress->prefix = prefix;
- progress->total = total;
- progress->last_percent = -1;
- progress->delay = 0;
- progress->need_lf = 0;
- if (snprintf(buf, sizeof(buf), title, total))
- fprintf(stderr, "%s\n", buf);
- set_progress_signal();
+ return display(progress, n, 0);
}
void start_progress_delay(struct progress *progress, const char *title,
- const char *prefix, unsigned total,
- unsigned percent_treshold, unsigned delay)
+ unsigned total, unsigned percent_treshold, unsigned delay)
{
- progress->prefix = prefix;
+ progress->title = title;
progress->total = total;
+ progress->last_value = -1;
progress->last_percent = -1;
progress->delayed_percent_treshold = percent_treshold;
- progress->delayed_title = title;
progress->delay = delay;
- progress->need_lf = 0;
set_progress_signal();
}
+void start_progress(struct progress *progress, const char *title, unsigned total)
+{
+ start_progress_delay(progress, title, total, 0, 0);
+}
+
void stop_progress(struct progress *progress)
{
+ if (progress->last_value != -1) {
+ /* Force the last update */
+ progress_update = 1;
+ display(progress, progress->last_value, 1);
+ }
clear_progress_signal();
- if (progress->need_lf)
- fputc('\n', stderr);
}