[gvfs] gvfs-copy: Make the progress output usable
- From: Ross Lagerwall <rossl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs] gvfs-copy: Make the progress output usable
- Date: Fri, 18 Apr 2014 19:32:15 +0000 (UTC)
commit c12758233bbeef5728e1589d908106ac5d1f1417
Author: Ross Lagerwall <rosslagerwall gmail com>
Date: Thu Apr 17 08:18:14 2014 +0100
gvfs-copy: Make the progress output usable
Rather than spamming the screen with output, rate-limit the updates and
make them display over each other.
https://bugzilla.gnome.org/show_bug.cgi?id=637543
programs/gvfs-copy.c | 38 ++++++++++++++++++++++++++------------
1 files changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/programs/gvfs-copy.c b/programs/gvfs-copy.c
index 7a61dcf..14d569c 100644
--- a/programs/gvfs-copy.c
+++ b/programs/gvfs-copy.c
@@ -65,22 +65,34 @@ is_dir (GFile *file)
return res;
}
-static GTimeVal start_time;
+static gint64 start_time;
+static gint64 previous_time;
static void
show_progress (goffset current_num_bytes,
goffset total_num_bytes,
gpointer user_data)
{
- GTimeVal tv;
- char *size;
-
- g_get_current_time (&tv);
-
- size = g_format_size (current_num_bytes / MAX (tv.tv_sec - start_time.tv_sec, 1));
- g_print (_("progress"));
- g_print (" %"G_GINT64_FORMAT"/%"G_GINT64_FORMAT" (%s/s)\n",
- current_num_bytes, total_num_bytes, size);
- g_free (size);
+ gint64 tv;
+ char *current_size, *total_size, *rate;
+
+ tv = g_get_monotonic_time ();
+ if (tv - previous_time < (G_USEC_PER_SEC / 5) &&
+ current_num_bytes != total_num_bytes)
+ return;
+
+ current_size = g_format_size (current_num_bytes);
+ total_size = g_format_size (total_num_bytes);
+ rate = g_format_size (current_num_bytes /
+ MAX ((tv - start_time) / G_USEC_PER_SEC, 1));
+ g_print ("\r\033[K");
+ g_print (_("Transferred %s out of %s (%s/s)"),
+ current_size, total_size, rate);
+
+ previous_time = tv;
+
+ g_free (current_size);
+ g_free (total_size);
+ g_free (rate);
}
static void
@@ -195,7 +207,7 @@ main (int argc, char *argv[])
error = NULL;
- g_get_current_time (&start_time);
+ start_time = g_get_monotonic_time ();
if (!g_file_copy (source, target, flags, NULL, progress?show_progress:NULL, NULL, &error))
{
if (interactive && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
@@ -225,6 +237,8 @@ main (int argc, char *argv[])
retval = 1;
}
}
+ if (progress && retval == 0)
+ g_print("\n");
g_object_unref (source);
g_object_unref (target);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]