summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-08-26 22:03:47 +0100
committerRichard W.M. Jones <rjones@redhat.com>2011-08-26 22:03:47 +0100
commit75005e48bb54f25dcc99480d659dfe9353382a15 (patch)
tree8961e01d4d6b1f2f8bc32a2c9e3748c8d42e184a
parent2faef37957629e0436308e759211209e5e823ee0 (diff)
downloadlibguestfs-75005e48bb54f25dcc99480d659dfe9353382a15.tar.gz
libguestfs-75005e48bb54f25dcc99480d659dfe9353382a15.tar.xz
libguestfs-75005e48bb54f25dcc99480d659dfe9353382a15.zip
progress: Add machine readable flag.
Machine-readable progress bars look like: 0/100 1/100 2/100
-rw-r--r--fish/progress.c38
-rw-r--r--fish/progress.h1
2 files changed, 26 insertions, 13 deletions
diff --git a/fish/progress.c b/fish/progress.c
index 623dd0e5..ac98ca04 100644
--- a/fish/progress.c
+++ b/fish/progress.c
@@ -92,6 +92,7 @@ struct progress_bar {
struct rmsd rmsd; /* running mean and standard deviation */
int have_terminfo;
int utf8_mode;
+ int machine_readable;
};
struct progress_bar *
@@ -104,14 +105,22 @@ progress_bar_init (unsigned flags)
if (bar == NULL)
return NULL;
- bar->utf8_mode = STREQ (nl_langinfo (CODESET), "UTF-8");
+ if (flags & PROGRESS_BAR_MACHINE_READABLE) {
+ bar->machine_readable = 1;
+ bar->utf8_mode = 0;
+ bar->have_terminfo = 0;
+ } else {
+ bar->machine_readable = 0;
+
+ bar->utf8_mode = STREQ (nl_langinfo (CODESET), "UTF-8");
- bar->have_terminfo = 0;
+ bar->have_terminfo = 0;
- term = getenv ("TERM");
- if (term) {
- if (tgetent (NULL, term) == 1)
- bar->have_terminfo = 1;
+ term = getenv ("TERM");
+ if (term) {
+ if (tgetent (NULL, term) == 1)
+ bar->have_terminfo = 1;
+ }
}
/* Call this to ensure the other fields are in a reasonable state.
@@ -257,13 +266,7 @@ progress_bar_set (struct progress_bar *bar,
double ratio;
const char *s_open, *s_dot, *s_dash, *s_close;
- if (bar->utf8_mode) {
- s_open = "\u27e6"; s_dot = "\u2589"; s_dash = "\u2550"; s_close = "\u27e7";
- } else {
- s_open = "["; s_dot = "#"; s_dash = "-"; s_close = "]";
- }
-
- if (bar->have_terminfo == 0) {
+ if (bar->machine_readable || bar->have_terminfo == 0) {
dumb:
printf ("%" PRIu64 "/%" PRIu64 "\n", position, total);
} else {
@@ -292,6 +295,15 @@ progress_bar_set (struct progress_bar *bar,
fputs (" 100% ", stdout);
}
+ if (bar->utf8_mode) {
+ s_open = "\u27e6";
+ s_dot = "\u2589";
+ s_dash = "\u2550";
+ s_close = "\u27e7";
+ } else {
+ s_open = "["; s_dot = "#"; s_dash = "-"; s_close = "]";
+ }
+
fputs (s_open, stdout);
if (!pulse_mode) {
diff --git a/fish/progress.h b/fish/progress.h
index ad9d23a2..0e965f14 100644
--- a/fish/progress.h
+++ b/fish/progress.h
@@ -27,6 +27,7 @@ struct progress_bar;
*
* Function returns a handle, or NULL if there was an error.
*/
+#define PROGRESS_BAR_MACHINE_READABLE 1
extern struct progress_bar *progress_bar_init (unsigned flags);
/* This should be called at the start of each command. */