@@ -44,65 +44,6 @@ public class Monitor.Utils.Strings {
4444
4545}
4646
47- /**
48- * Static helper class for unit formatting
49- * Author: Laurent Callarec @lcallarec
50- */
51- public class Monitor.Utils.HumanUnitFormatter {
52- const string [] SIZE_UNITS = { " B" , " KiB" , " MiB" , " GiB" , " TiB" };
53- const string [] PACKED_SIZE_UNITS = { " B" , " K" , " M" , " G" , " T" };
54- const double KFACTOR = 1024 ;
55-
56- /**
57- * format a string of bytes to an human readable format with units
58- */
59- public static string string_bytes_to_human (string bytes , bool packed = false ) {
60- string [] units;
61-
62- if (packed)
63- units = HumanUnitFormatter . PACKED_SIZE_UNITS ;
64- else
65- units = HumanUnitFormatter . SIZE_UNITS ;
66-
67- double current_size = double . parse (bytes);
68- string current_size_formatted = bytes. to_string () + units[0 ];
69-
70- for (int i = 0 ; i <= units. length; i++ ) {
71- if (current_size < HumanUnitFormatter . KFACTOR ) {
72- return GLib . Math . round (current_size). to_string () + units[i];
73- }
74- current_size = current_size / HumanUnitFormatter . KFACTOR ;
75- }
76-
77- return current_size_formatted;
78- }
79-
80- public static string double_bytes_to_human (double bytes ) {
81- string units = _(" B" );
82-
83- // convert to MiB if needed
84- if (bytes > 1024.0 ) {
85- bytes / = 1024.0 ;
86- units = _(" KiB" );
87- }
88-
89- // convert to GiB if needed
90- if (bytes > 1024.0 ) {
91- bytes / = 1024.0 ;
92- units = _(" MiB" );
93- }
94-
95- if (bytes > 1024.0 ) {
96- bytes / = 1024.0 ;
97- units = _(" GiB" );
98- }
99-
100- return " %.1f %s " . printf (bytes, units);
101- }
102-
103- }
104-
105-
10647public class Monitor.Utils.Colors : Object {
10748
10849 public const string STRAWBERRY_100 = " #ff8c82" ;
0 commit comments