##// END OF EJS Templates
formatter: introduce isplain() to replace (the inverse of) __nonzero__() (API)...
Mathias De Maré -
r29949:e7cacb45 default
parent child Browse files
Show More
@@ -441,12 +441,12 b' def annotate(ui, repo, *pats, **opts):'
441 if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
441 if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
442 raise error.Abort(_('at least one of -n/-c is required for -l'))
442 raise error.Abort(_('at least one of -n/-c is required for -l'))
443
443
444 if fm:
444 if fm.isplain():
445 def makefunc(get, fmt):
446 return lambda x: fmt(get(x))
447 else:
445 def makefunc(get, fmt):
448 def makefunc(get, fmt):
446 return get
449 return get
447 else:
448 def makefunc(get, fmt):
449 return lambda x: fmt(get(x))
450 funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap
450 funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap
451 if opts.get(op)]
451 if opts.get(op)]
452 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
452 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
@@ -476,12 +476,12 b' def annotate(ui, repo, *pats, **opts):'
476
476
477 for f, sep in funcmap:
477 for f, sep in funcmap:
478 l = [f(n) for n, dummy in lines]
478 l = [f(n) for n, dummy in lines]
479 if fm:
479 if fm.isplain():
480 formats.append(['%s' for x in l])
481 else:
482 sizes = [encoding.colwidth(x) for x in l]
480 sizes = [encoding.colwidth(x) for x in l]
483 ml = max(sizes)
481 ml = max(sizes)
484 formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes])
482 formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes])
483 else:
484 formats.append(['%s' for x in l])
485 pieces.append(l)
485 pieces.append(l)
486
486
487 for f, p, l in zip(zip(*formats), zip(*pieces), lines):
487 for f, p, l in zip(zip(*formats), zip(*pieces), lines):
@@ -1185,7 +1185,7 b' def bookmark(ui, repo, *names, **opts):'
1185 fm = ui.formatter('bookmarks', opts)
1185 fm = ui.formatter('bookmarks', opts)
1186 hexfn = fm.hexfunc
1186 hexfn = fm.hexfunc
1187 marks = repo._bookmarks
1187 marks = repo._bookmarks
1188 if len(marks) == 0 and not fm:
1188 if len(marks) == 0 and fm.isplain():
1189 ui.status(_("no bookmarks set\n"))
1189 ui.status(_("no bookmarks set\n"))
1190 for bmark, n in sorted(marks.iteritems()):
1190 for bmark, n in sorted(marks.iteritems()):
1191 active = repo._activebookmark
1191 active = repo._activebookmark
@@ -4442,10 +4442,10 b' def grep(ui, repo, pattern, *pats, **opt'
4442
4442
4443 def display(fm, fn, ctx, pstates, states):
4443 def display(fm, fn, ctx, pstates, states):
4444 rev = ctx.rev()
4444 rev = ctx.rev()
4445 if fm:
4445 if fm.isplain():
4446 formatuser = ui.shortuser
4447 else:
4446 formatuser = str
4448 formatuser = str
4447 else:
4448 formatuser = ui.shortuser
4449 if ui.quiet:
4449 if ui.quiet:
4450 datefmt = '%Y-%m-%d'
4450 datefmt = '%Y-%m-%d'
4451 else:
4451 else:
@@ -5695,10 +5695,10 b' def paths(ui, repo, search=None, **opts)'
5695 pathitems = sorted(ui.paths.iteritems())
5695 pathitems = sorted(ui.paths.iteritems())
5696
5696
5697 fm = ui.formatter('paths', opts)
5697 fm = ui.formatter('paths', opts)
5698 if fm:
5698 if fm.isplain():
5699 hidepassword = util.hidepassword
5700 else:
5699 hidepassword = str
5701 hidepassword = str
5700 else:
5701 hidepassword = util.hidepassword
5702 if ui.quiet:
5702 if ui.quiet:
5703 namefmt = '%s\n'
5703 namefmt = '%s\n'
5704 else:
5704 else:
@@ -57,10 +57,6 b' class baseformatter(object):'
57 def __exit__(self, exctype, excvalue, traceback):
57 def __exit__(self, exctype, excvalue, traceback):
58 if exctype is None:
58 if exctype is None:
59 self.end()
59 self.end()
60 def __nonzero__(self):
61 '''return False if we're not doing real templating so we can
62 skip extra work'''
63 return True
64 def _showitem(self):
60 def _showitem(self):
65 '''show a formatted item once all data is collected'''
61 '''show a formatted item once all data is collected'''
66 pass
62 pass
@@ -96,6 +92,9 b' class baseformatter(object):'
96 def plain(self, text, **opts):
92 def plain(self, text, **opts):
97 '''show raw text for non-templated mode'''
93 '''show raw text for non-templated mode'''
98 pass
94 pass
95 def isplain(self):
96 '''check for plain formatter usage'''
97 return False
99 def nested(self, field):
98 def nested(self, field):
100 '''sub formatter to store nested data in the specified field'''
99 '''sub formatter to store nested data in the specified field'''
101 self._item[field] = data = []
100 self._item[field] = data = []
@@ -142,8 +141,6 b' class plainformatter(baseformatter):'
142 self.hexfunc = hex
141 self.hexfunc = hex
143 else:
142 else:
144 self.hexfunc = short
143 self.hexfunc = short
145 def __nonzero__(self):
146 return False
147 def startitem(self):
144 def startitem(self):
148 pass
145 pass
149 def data(self, **data):
146 def data(self, **data):
@@ -156,6 +153,8 b' class plainformatter(baseformatter):'
156 self._ui.write(deftext % fielddata, **opts)
153 self._ui.write(deftext % fielddata, **opts)
157 def plain(self, text, **opts):
154 def plain(self, text, **opts):
158 self._ui.write(text, **opts)
155 self._ui.write(text, **opts)
156 def isplain(self):
157 return True
159 def nested(self, field):
158 def nested(self, field):
160 # nested data will be directly written to ui
159 # nested data will be directly written to ui
161 return self
160 return self
General Comments 0
You need to be logged in to leave comments. Login now