diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2014-04-17 08:18:14 +0100 |
---|---|---|
committer | Ross Lagerwall <rosslagerwall@gmail.com> | 2014-04-18 20:31:43 +0100 |
commit | c12758233bbeef5728e1589d908106ac5d1f1417 (patch) | |
tree | a14346956b1b7baf4f7c33d9449ec3a29cb2a4d5 | |
parent | 57e9a7f28aac02d8f27ef15d76440a0aa4dd2973 (diff) | |
download | gvfs-c12758233bbeef5728e1589d908106ac5d1f1417.tar.gz |
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
-rw-r--r-- | 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 7a61dcf8..14d569cc 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); |