comparison mercurial/formatter.py @ 29949:e7cacb45c4be

formatter: introduce isplain() to replace (the inverse of) __nonzero__() (API) V2: also remove and replace __nonzero__
author Mathias De Maré <mathias.demare@gmail.com>
date Mon, 29 Aug 2016 17:19:09 +0200
parents 307b20e5e505
children 783016005122
comparison
equal deleted inserted replaced
29948:e40343ce9c4c 29949:e7cacb45c4be
55 def __enter__(self): 55 def __enter__(self):
56 return self 56 return self
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
67 def startitem(self): 63 def startitem(self):
68 '''begin an item in the format list''' 64 '''begin an item in the format list'''
94 assert len(fieldkeys) == len(fielddata) 90 assert len(fieldkeys) == len(fielddata)
95 self._item.update(zip(fieldkeys, fielddata)) 91 self._item.update(zip(fieldkeys, fielddata))
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 = []
102 return _nestedformatter(self._ui, self._converter, data) 101 return _nestedformatter(self._ui, self._converter, data)
103 def end(self): 102 def end(self):
140 baseformatter.__init__(self, ui, topic, opts, _plainconverter) 139 baseformatter.__init__(self, ui, topic, opts, _plainconverter)
141 if ui.debugflag: 140 if ui.debugflag:
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):
150 pass 147 pass
151 def write(self, fields, deftext, *fielddata, **opts): 148 def write(self, fields, deftext, *fielddata, **opts):
154 '''do conditional write''' 151 '''do conditional write'''
155 if cond: 152 if cond:
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
162 def end(self): 161 def end(self):
163 pass 162 pass