mercurial/formatter.py
changeset 37597 d110167610db
parent 37596 8c121a9837ca
child 37770 31750413f8d7
equal deleted inserted replaced
37596:8c121a9837ca 37597:d110167610db
   158 
   158 
   159 class baseformatter(object):
   159 class baseformatter(object):
   160     def __init__(self, ui, topic, opts, converter):
   160     def __init__(self, ui, topic, opts, converter):
   161         self._ui = ui
   161         self._ui = ui
   162         self._topic = topic
   162         self._topic = topic
       
   163         self._opts = opts
   163         self._converter = converter
   164         self._converter = converter
   164         self._item = None
   165         self._item = None
   165         # function to convert node to string suitable for this output
   166         # function to convert node to string suitable for this output
   166         self.hexfunc = hex
   167         self.hexfunc = hex
   167     def __enter__(self):
   168     def __enter__(self):
   220     def end(self):
   221     def end(self):
   221         '''end output for the formatter'''
   222         '''end output for the formatter'''
   222         if self._item is not None:
   223         if self._item is not None:
   223             self._showitem()
   224             self._showitem()
   224 
   225 
   225 def nullformatter(ui, topic):
   226 def nullformatter(ui, topic, opts):
   226     '''formatter that prints nothing'''
   227     '''formatter that prints nothing'''
   227     return baseformatter(ui, topic, opts={}, converter=_nullconverter)
   228     return baseformatter(ui, topic, opts, converter=_nullconverter)
   228 
   229 
   229 class _nestedformatter(baseformatter):
   230 class _nestedformatter(baseformatter):
   230     '''build sub items and store them in the parent formatter'''
   231     '''build sub items and store them in the parent formatter'''
   231     def __init__(self, ui, converter, data):
   232     def __init__(self, ui, converter, data):
   232         baseformatter.__init__(self, ui, topic='', opts={}, converter=converter)
   233         baseformatter.__init__(self, ui, topic='', opts={}, converter=converter)
   593 
   594 
   594 @contextlib.contextmanager
   595 @contextlib.contextmanager
   595 def _neverending(fm):
   596 def _neverending(fm):
   596     yield fm
   597     yield fm
   597 
   598 
   598 def maybereopen(fm, filename, opts):
   599 def maybereopen(fm, filename):
   599     """Create a formatter backed by file if filename specified, else return
   600     """Create a formatter backed by file if filename specified, else return
   600     the given formatter
   601     the given formatter
   601 
   602 
   602     Must be invoked using the 'with' statement. This will never call fm.end()
   603     Must be invoked using the 'with' statement. This will never call fm.end()
   603     of the given formatter.
   604     of the given formatter.
   604     """
   605     """
   605     if filename:
   606     if filename:
   606         return openformatter(fm._ui, filename, fm._topic, opts)
   607         return openformatter(fm._ui, filename, fm._topic, fm._opts)
   607     else:
   608     else:
   608         return _neverending(fm)
   609         return _neverending(fm)