diff options
author | hubertf <hubertf@NetBSD.org> | 2004-03-09 17:04:24 +0000 |
---|---|---|
committer | hubertf <hubertf@NetBSD.org> | 2004-03-09 17:04:24 +0000 |
commit | d9415b521c515095fba42397975441dfbfb487d8 (patch) | |
tree | 731648ee58873672e9ead73fa33f3321931c48cc /progressbar.c | |
parent | 3cac59fa5b5b8e6ebd1ec4c9a16728fcfa27cd9b (diff) | |
download | bsd-progress-d9415b521c515095fba42397975441dfbfb487d8.tar.gz bsd-progress-d9415b521c515095fba42397975441dfbfb487d8.tar.zst bsd-progress-d9415b521c515095fba42397975441dfbfb487d8.zip |
Allow custom text printed before (left of) the progress bar from progress(1):
miyu# cat openoffice-linux-1.1.0.tgz | progress -z -p 'Bytes written: ' dd of=/dev/null bs=1m
Bytes written: 193 MB 13.83 MB/s 0+195211 records in
and:
miyu# progress -f openoffice-linux-1.1.0.tgz -z -p 'Bytes written: ' dd of=/dev/null bs=1m
Bytes written: 28% |****** | 57919 KB 14.12 MB/s 00:09 ETA
OK'd by lukem.
Diffstat (limited to 'progressbar.c')
-rw-r--r-- | progressbar.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/progressbar.c b/progressbar.c index f096ffc..9c09147 100644 --- a/progressbar.c +++ b/progressbar.c @@ -1,4 +1,4 @@ -/* $NetBSD: progressbar.c,v 1.4 2003/07/17 12:06:18 lukem Exp $ */ +/* $NetBSD: progressbar.c,v 1.5 2004/03/09 17:04:24 hubertf Exp $ */ /*- * Copyright (c) 1997-2003 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: progressbar.c,v 1.4 2003/07/17 12:06:18 lukem Exp $"); +__RCSID("$NetBSD: progressbar.c,v 1.5 2004/03/09 17:04:24 hubertf Exp $"); #endif /* not lint */ /* @@ -52,6 +52,7 @@ __RCSID("$NetBSD: progressbar.c,v 1.4 2003/07/17 12:06:18 lukem Exp $"); #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include <tzfile.h> #include <unistd.h> @@ -200,6 +201,8 @@ progressmeter(int flag) return; len += snprintf(buf + len, BUFLEFT, "\r"); + if (prefix) + len += snprintf(buf + len, BUFLEFT, "%s", prefix); if (filesize > 0) { ratio = (int)((double)cursize * 100.0 / (double)filesize); ratio = MAX(ratio, 0); @@ -211,6 +214,8 @@ progressmeter(int flag) * the number of stars won't exceed the buffer size */ barlength = MIN(sizeof(buf) - 1, ttywidth) - BAROVERHEAD; + if (prefix) + barlength -= strlen(prefix); if (barlength > 0) { i = barlength * ratio / 100; len += snprintf(buf + len, BUFLEFT, |