From ded41d3d8f1033c4f656f69b16daf5e2a53a6b4f Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 29 Mar 2006 03:17:46 +0000 Subject: [PATCH] Create a single colorize() function in the output module and use it to generate all of the existing color functions. svn path=/main/trunk/; revision=3030 --- pym/output.py | 65 +++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 44 deletions(-) diff --git a/pym/output.py b/pym/output.py index f23bac263..e735d4d47 100644 --- a/pym/output.py +++ b/pym/output.py @@ -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)) -- 2.26.2