]> git.itanic.dy.fi Git - emerge-timer/commitdiff
give_time(): Add nocolor option
authorEsko Kokkonen <esko.kokkonen@gmail.com>
Sat, 24 Sep 2011 14:32:24 +0000 (17:32 +0300)
committerEsko Kokkonen <esko.kokkonen@gmail.com>
Sat, 24 Sep 2011 14:32:24 +0000 (17:32 +0300)
Calling the noclor=True causes the function to return the time string
without the colors.

emerge-timer.py

index 137ce4305b1f67b4f4e01194699263ccefa88d10..9ab7cabf304f2beed9517190d7c50517784a4cfd 100755 (executable)
@@ -154,8 +154,14 @@ class package:
 
 
 
-def give_time(time):
+def give_time(time, nocolor=False):
     """Converts time in seconds to human readable form"""
+    global green_start, color_stop
+
+    if nocolor == True:
+        green_start = ""
+        color_stop = ""
+
     days = time/(3600*24)
     hours = (days - int(days))*24
     minutes = (hours - int(hours))*60
@@ -198,6 +204,9 @@ def give_time(time):
         pseconds = (green_start + str(seconds) +
                     color_stop + " seconds ")
 
+    green_start = "\033[32m"
+    color_stop = "\033[m"
+
     return (pdays + phours + pminutes + pseconds)