Create a single colorize() function in the output module and use it to generate all...
authorZac Medico <zmedico@gentoo.org>
Wed, 29 Mar 2006 03:17:46 +0000 (03:17 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 29 Mar 2006 03:17:46 +0000 (03:17 -0000)
svn path=/main/trunk/; revision=3030

pym/output.py

index f23bac263222a327eb20421c16e4b4af0f3af83b..e735d4d4762d18203fd73462cb6eb7edcb934f25 100644 (file)
@@ -132,47 +132,24 @@ def nocolor():
 def resetColor():
        return codes["reset"]
 
-def ctext(color,text):
-       return codes[ctext]+text+codes["reset"]
-
-def bold(text):
-       return codes["bold"]+text+codes["reset"]
-def white(text):
-       return bold(text)
-
-def teal(text):
-       return codes["teal"]+text+codes["reset"]
-def turquoise(text):
-       return codes["turquoise"]+text+codes["reset"]
-def darkteal(text):
-       return turquoise(text)
-
-def fuscia(text): # Don't use this one. It's spelled wrong!
-       return codes["fuchsia"]+text+codes["reset"]
-def fuchsia(text):
-       return codes["fuchsia"]+text+codes["reset"]
-def purple(text):
-       return codes["purple"]+text+codes["reset"]
-
-def blue(text):
-       return codes["blue"]+text+codes["reset"]
-def darkblue(text):
-       return codes["darkblue"]+text+codes["reset"]
-
-def green(text):
-       return codes["green"]+text+codes["reset"]
-def darkgreen(text):
-       return codes["darkgreen"]+text+codes["reset"]
-
-def yellow(text):
-       return codes["yellow"]+text+codes["reset"]
-def brown(text):
-       return codes["brown"]+text+codes["reset"]
-def darkyellow(text):
-       return brown(text)
-
-def red(text):
-       return codes["red"]+text+codes["reset"]
-def darkred(text):
-       return codes["darkred"]+text+codes["reset"]
-
+def colorize(color_key, text):
+       return codes[color_key] + text + codes["reset"]
+
+codes["darkteal"]   = codes["turquoise"]
+codes["darkyellow"] = codes["brown"]
+codes["fuscia"]     = codes["fuchsia"]
+codes["white"]      = codes["bold"]
+
+compat_functions_colors = ["bold","white","teal","turquoise","darkteal",
+       "fuscia","fuchsia","purple","blue","darkblue","green","darkgreen","yellow",
+       "brown","darkyellow","red","darkred"]
+
+def create_color_func(color_key):
+       def derived_func(*args):
+               newargs = list(args)
+               newargs.insert(0, color_key)
+               return colorize(*newargs)
+       return derived_func
+
+for c in compat_functions_colors:
+       setattr(sys.modules[__name__], c, create_color_func(c))