summarylogtreecommitdiffstats
path: root/ps-item-stats-human-sizes_all.patch
blob: da8516b2fc52cbc5881da6aeaa78f0f2449b9815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--- a/src/display/utils.cc
+++ b/src/display/utils.cc
@@ -133,6 +133,8 @@ print_download_title(char* first, char*
   return print_buffer(first, last, " %s", d->info()->name().c_str());
 }
 
+std::string human_size(int64_t bytes, unsigned int format=0);
+
 char*
 print_download_info_full(char* first, char* last, core::Download* d) {
   if (!d->download()->info()->is_open())
@@ -142,17 +144,18 @@ print_download_info_full(char* first, ch
   else
     first = print_buffer(first, last, "          ");
 
+  std::string h_size = human_size(d->download()->file_list()->size_bytes(), 0);
+  std::string h_done = human_size(d->download()->bytes_done(), 0);
   if (d->is_done())
-    first = print_buffer(first, last, "done %10.1f MB", (double)d->download()->file_list()->size_bytes() / (double)(1 << 20));
+    first = print_buffer(first, last, "  done   %s   ", h_size.c_str());
   else
-    first = print_buffer(first, last, "%6.1f / %6.1f MB",
-                         (double)d->download()->bytes_done() / (double)(1 << 20),
-                         (double)d->download()->file_list()->size_bytes() / (double)(1 << 20));
-  
-  first = print_buffer(first, last, " Rate: %5.1f / %5.1f KB Uploaded: %7.1f MB",
-                       (double)d->info()->up_rate()->rate() / (1 << 10),
-                       (double)d->info()->down_rate()->rate() / (1 << 10),
-                       (double)d->info()->up_rate()->total() / (1 << 20));
+    first = print_buffer(first, last, "%s / %s   ", h_done.c_str(), h_size.c_str());
+
+  std::string h_up   = human_size(d->info()->up_rate()->rate(), 0);
+  std::string h_down = human_size(d->info()->down_rate()->rate(), 0);
+  std::string h_sum  = human_size(d->info()->up_rate()->total(), 0);
+  first = print_buffer(first, last, " Rate: %s / %s  Uploaded: %s    ",
+                       h_up.c_str(), h_down.c_str(), h_sum.c_str());
 
   if (d->download()->info()->is_active() && !d->is_done()) {
     first = print_buffer(first, last, " ");