Add nofmt_printer to color.py
The current printer always expands on the arguments which is a problem
for strings containing %.
Instead of forcing manual string expansion before printing allow for a
no format printer option which simply accepts and prints the string.
Part of fix for issue #131:
http://code.google.com/p/git-repo/issues/detail?id=131
Change-Id: I08ef94b9c4ddab58ac12d2bd32ebd2c413e4f83b
diff --git a/color.py b/color.py
index d856313..7970198 100644
--- a/color.py
+++ b/color.py
@@ -126,6 +126,13 @@
s._out.write(c(fmt, *args))
return f
+ def nofmt_printer(self, opt=None, fg=None, bg=None, attr=None):
+ s = self
+ c = self.nofmt_colorer(opt, fg, bg, attr)
+ def f(fmt):
+ s._out.write(c(fmt))
+ return f
+
def colorer(self, opt=None, fg=None, bg=None, attr=None):
if self._on:
c = self._parse(opt, fg, bg, attr)
@@ -138,6 +145,17 @@
return fmt % args
return f
+ def nofmt_colorer(self, opt=None, fg=None, bg=None, attr=None):
+ if self._on:
+ c = self._parse(opt, fg, bg, attr)
+ def f(fmt):
+ return ''.join([c, fmt, RESET])
+ return f
+ else:
+ def f(fmt):
+ return fmt
+ return f
+
def _parse(self, opt, fg, bg, attr):
if not opt:
return _Color(fg, bg, attr)