comparison mercurial/ui.py @ 40589:054d0fcba2c4

commandserver: add experimental option to use separate message channel This is loosely based on the idea of the TortoiseHg's pipeui extension, which attaches ui.label to message text so the command-server client can capture prompt text, for example. https://bitbucket.org/tortoisehg/thg/src/4.7.2/tortoisehg/util/pipeui.py I was thinking that this functionality could be generalized to templating, but changed mind as doing template stuff would be unnecessarily complex. It's merely a status message, a simple serialization option should suffice. Since this slightly changes the command-server protocol, it's gated by a config knob. If the config is enabled, and if it's supported by the server, "message-encoding: <name>" is advertised so the client can stop parsing 'o'/'e' channel data and read encoded messages from the 'm' channel. As we might add new message encodings in future releases, client can specify a list of encoding names in preferred order. This patch includes 'cbor' encoding as example. Perhaps, 'json' should be supported as well.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 18 Jan 2015 18:49:59 +0900
parents 5542bc9125c9
children 83dd8c63a0c6
comparison
equal deleted inserted replaced
40588:9683dfb6f13a 40589:054d0fcba2c4
1010 # opencode timeblockedsection because this is a critical path 1010 # opencode timeblockedsection because this is a critical path
1011 starttime = util.timer() 1011 starttime = util.timer()
1012 try: 1012 try:
1013 if dest is self._ferr and not getattr(self._fout, 'closed', False): 1013 if dest is self._ferr and not getattr(self._fout, 'closed', False):
1014 self._fout.flush() 1014 self._fout.flush()
1015 if self._colormode == 'win32': 1015 if getattr(dest, 'structured', False):
1016 # channel for machine-readable output with metadata, where
1017 # no extra colorization is necessary.
1018 dest.write(msg, **opts)
1019 elif self._colormode == 'win32':
1016 # windows color printing is its own can of crab, defer to 1020 # windows color printing is its own can of crab, defer to
1017 # the color module and that is it. 1021 # the color module and that is it.
1018 color.win32print(self, dest.write, msg, **opts) 1022 color.win32print(self, dest.write, msg, **opts)
1019 else: 1023 else:
1020 if self._colormode is not None: 1024 if self._colormode is not None:
1960 def haveprogbar(): 1964 def haveprogbar():
1961 return _progresssingleton is not None 1965 return _progresssingleton is not None
1962 1966
1963 def _selectmsgdests(ui): 1967 def _selectmsgdests(ui):
1964 name = ui.config(b'ui', b'message-output') 1968 name = ui.config(b'ui', b'message-output')
1969 if name == b'channel':
1970 if ui.fmsg:
1971 return ui.fmsg, ui.fmsg
1972 else:
1973 # fall back to ferr if channel isn't ready so that status/error
1974 # messages can be printed
1975 return ui.ferr, ui.ferr
1965 if name == b'stdio': 1976 if name == b'stdio':
1966 return ui.fout, ui.ferr 1977 return ui.fout, ui.ferr
1967 if name == b'stderr': 1978 if name == b'stderr':
1968 return ui.ferr, ui.ferr 1979 return ui.ferr, ui.ferr
1969 raise error.Abort(b'invalid ui.message-output destination: %s' % name) 1980 raise error.Abort(b'invalid ui.message-output destination: %s' % name)