diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-17 10:44:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-17 10:44:01 +0000 |
commit | c9f35cfcad1112803a3b09ce5530a2d7752115ee (patch) | |
tree | 6443059b3a15a5629c9dee1e3be42952416dc306 /src/fs/gnunet-download.c | |
parent | 0190de8cfcc807dee7239b58f5dd71a7fe9b8668 (diff) | |
download | gnunet-c9f35cfcad1112803a3b09ce5530a2d7752115ee.tar.gz gnunet-c9f35cfcad1112803a3b09ce5530a2d7752115ee.zip |
-fix #2354
Diffstat (limited to 'src/fs/gnunet-download.c')
-rw-r--r-- | src/fs/gnunet-download.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index bd5b09c0d..aa1da8f3d 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c | |||
@@ -75,6 +75,41 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
75 | 75 | ||
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Display progress bar (if tty). | ||
79 | * | ||
80 | * @param x current position in the download | ||
81 | * @param n total size of the download | ||
82 | * @param w desired number of steps in the progress bar | ||
83 | */ | ||
84 | static void | ||
85 | display_bar (unsigned long long x, | ||
86 | unsigned long long n, | ||
87 | unsigned int w) | ||
88 | { | ||
89 | char buf[w + 20]; | ||
90 | unsigned int p; | ||
91 | unsigned int endeq; | ||
92 | float ratio_complete; | ||
93 | |||
94 | #ifndef MINGW | ||
95 | if (0 == isatty (1)) | ||
96 | return; | ||
97 | #endif | ||
98 | ratio_complete = x/(float)n; | ||
99 | endeq = ratio_complete * w; | ||
100 | GNUNET_snprintf (buf, sizeof (buf), | ||
101 | "%3d%% [", (int)(ratio_complete*100) ); | ||
102 | for (p=0; p<endeq; p++) | ||
103 | strcat (buf, "="); | ||
104 | for (p=endeq; p<w; p++) | ||
105 | strcat (buf, " "); | ||
106 | strcat (buf, "]\r"); | ||
107 | printf (buf); | ||
108 | fflush(stdout); | ||
109 | } | ||
110 | |||
111 | |||
112 | /** | ||
78 | * Called by FS client to give information about the progress of an | 113 | * Called by FS client to give information about the progress of an |
79 | * operation. | 114 | * operation. |
80 | * | 115 | * |
@@ -124,6 +159,12 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
124 | GNUNET_free (s2); | 159 | GNUNET_free (s2); |
125 | GNUNET_free (t); | 160 | GNUNET_free (t); |
126 | } | 161 | } |
162 | else | ||
163 | { | ||
164 | display_bar (info->value.download.completed, | ||
165 | info->value.download.size, | ||
166 | 60); | ||
167 | } | ||
127 | break; | 168 | break; |
128 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 169 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
129 | FPRINTF (stderr, _("Error downloading: %s.\n"), | 170 | FPRINTF (stderr, _("Error downloading: %s.\n"), |