gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22059 - gnunet/src/fs


From: gnunet
Subject: [GNUnet-SVN] r22059 - gnunet/src/fs
Date: Sun, 17 Jun 2012 12:44:01 +0200

Author: grothoff
Date: 2012-06-17 12:44:01 +0200 (Sun, 17 Jun 2012)
New Revision: 22059

Modified:
   gnunet/src/fs/gnunet-download.c
Log:
-fix #2354


Modified: gnunet/src/fs/gnunet-download.c
===================================================================
--- gnunet/src/fs/gnunet-download.c     2012-06-17 10:08:15 UTC (rev 22058)
+++ gnunet/src/fs/gnunet-download.c     2012-06-17 10:44:01 UTC (rev 22059)
@@ -75,6 +75,41 @@
 
 
 /**
+ * Display progress bar (if tty).
+ *
+ * @param x current position in the download
+ * @param n total size of the download
+ * @param w desired number of steps in the progress bar
+ */
+static void 
+display_bar (unsigned long long x, 
+            unsigned long long n, 
+            unsigned int w)
+{
+  char buf[w + 20];
+  unsigned int p;
+  unsigned int endeq;
+  float ratio_complete;
+
+#ifndef MINGW
+  if (0 == isatty (1))
+    return;
+#endif
+  ratio_complete = x/(float)n;
+  endeq = ratio_complete * w;
+  GNUNET_snprintf (buf, sizeof (buf),
+                  "%3d%% [", (int)(ratio_complete*100) );
+  for (p=0; p<endeq; p++)
+    strcat (buf, "=");
+  for (p=endeq; p<w; p++)
+    strcat (buf, " ");
+  strcat (buf, "]\r");
+  printf (buf);
+  fflush(stdout);
+}
+
+
+/**
  * Called by FS client to give information about the progress of an
  * operation.
  *
@@ -124,6 +159,12 @@
       GNUNET_free (s2);
       GNUNET_free (t);
     }
+    else
+    {
+      display_bar (info->value.download.completed,
+                  info->value.download.size,
+                  60);
+    }
     break;
   case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
     FPRINTF (stderr, _("Error downloading: %s.\n"),




reply via email to

[Prev in Thread] Current Thread [Next in Thread]