]> git.itanic.dy.fi Git - emerge-timer/commitdiff
print_versions(): Pad strings correctly when colors are used
authorEsko Kokkonen <esko.kokkonen@gmail.com>
Sat, 24 Sep 2011 14:36:16 +0000 (17:36 +0300)
committerEsko Kokkonen <esko.kokkonen@gmail.com>
Sat, 24 Sep 2011 14:36:16 +0000 (17:36 +0300)
Color characters aren't counted when they appear in the screen, but
len() does count them, so we need a special fix for the padding to
work properly in these cases.

emerge-timer.py

index 9ab7cabf304f2beed9517190d7c50517784a4cfd..7ac3f37083eab7eeba3215e1e5551dc3c3f74fa0 100755 (executable)
@@ -102,15 +102,17 @@ class package:
                 if len(p[0]) > version_length:
                     version_length = len(p[0])
 
-                if len(give_time(p[1])) > time_length:
-                    time_length = len(give_time(p[1]))
+                if len(give_time(p[1], True)) > time_length:
+                    time_length = len(give_time(p[1], True))
 
             for p in self.versions:
 
+                pad = time_length - len(give_time(p[1], True))
+
                 print('-'*90 + "\n" +
                       green_start + self.name + (p[0]).ljust(version_length) +
-                      color_stop + "  >>>  " + (give_time(p[1])).ljust(time_length)
-                      "  >>>  " + give_date(p[2]))
+                      color_stop + "  >>>  " + (give_time(p[1])) + " "*pad +
+                      "  >>>  " + give_date(p[2]))
 
         print('-'*90 + "\n" + "Package " + green_start +
               self.name + color_stop + " emerged " +