mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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
This commit is contained in:
parent
5f434ed723
commit
b75415075c
18
color.py
18
color.py
@ -126,6 +126,13 @@ class Coloring(object):
|
||||
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 @@ class Coloring(object):
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user