From: Esko Kokkonen Date: Sat, 24 Sep 2011 14:32:24 +0000 (+0300) Subject: give_time(): Add nocolor option X-Git-Url: http://git.itanic.dy.fi/?p=emerge-timer;a=commitdiff_plain;h=82d8f4b933a7929b707ce65e50d02ac71df0247f give_time(): Add nocolor option Calling the noclor=True causes the function to return the time string without the colors. --- diff --git a/emerge-timer.py b/emerge-timer.py index 137ce43..9ab7cab 100755 --- a/emerge-timer.py +++ b/emerge-timer.py @@ -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)