summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlof Johansson <olof.johansson@sonymobile.com>2013-02-26 07:36:03 +0100
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2013-02-26 16:04:55 +0900
commitb75415075c00bb17e14c5666a380b7e940db8c84 (patch)
tree2d94ac7c8db65324f038d3c666251848caddfa72
parent5f434ed723ac14cdcea12d038c066c0653e1ef3a (diff)
downloadgit-repo-b75415075c00bb17e14c5666a380b7e940db8c84.tar.gz
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
-rw-r--r--color.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/color.py b/color.py
index d856313f..7970198a 100644
--- a/color.py
+++ b/color.py
@@ -126,6 +126,13 @@ class Coloring(object):
126 s._out.write(c(fmt, *args)) 126 s._out.write(c(fmt, *args))
127 return f 127 return f
128 128
129 def nofmt_printer(self, opt=None, fg=None, bg=None, attr=None):
130 s = self
131 c = self.nofmt_colorer(opt, fg, bg, attr)
132 def f(fmt):
133 s._out.write(c(fmt))
134 return f
135
129 def colorer(self, opt=None, fg=None, bg=None, attr=None): 136 def colorer(self, opt=None, fg=None, bg=None, attr=None):
130 if self._on: 137 if self._on:
131 c = self._parse(opt, fg, bg, attr) 138 c = self._parse(opt, fg, bg, attr)
@@ -138,6 +145,17 @@ class Coloring(object):
138 return fmt % args 145 return fmt % args
139 return f 146 return f
140 147
148 def nofmt_colorer(self, opt=None, fg=None, bg=None, attr=None):
149 if self._on:
150 c = self._parse(opt, fg, bg, attr)
151 def f(fmt):
152 return ''.join([c, fmt, RESET])
153 return f
154 else:
155 def f(fmt):
156 return fmt
157 return f
158
141 def _parse(self, opt, fg, bg, attr): 159 def _parse(self, opt, fg, bg, attr):
142 if not opt: 160 if not opt:
143 return _Color(fg, bg, attr) 161 return _Color(fg, bg, attr)