Mercurial > public > mercurial-scm > hg
diff 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 |
line wrap: on
line diff
--- a/mercurial/ui.py Wed Nov 07 22:37:51 2018 +0900 +++ b/mercurial/ui.py Sun Jan 18 18:49:59 2015 +0900 @@ -1012,7 +1012,11 @@ try: if dest is self._ferr and not getattr(self._fout, 'closed', False): self._fout.flush() - if self._colormode == 'win32': + if getattr(dest, 'structured', False): + # channel for machine-readable output with metadata, where + # no extra colorization is necessary. + dest.write(msg, **opts) + elif self._colormode == 'win32': # windows color printing is its own can of crab, defer to # the color module and that is it. color.win32print(self, dest.write, msg, **opts) @@ -1962,6 +1966,13 @@ def _selectmsgdests(ui): name = ui.config(b'ui', b'message-output') + if name == b'channel': + if ui.fmsg: + return ui.fmsg, ui.fmsg + else: + # fall back to ferr if channel isn't ready so that status/error + # messages can be printed + return ui.ferr, ui.ferr if name == b'stdio': return ui.fout, ui.ferr if name == b'stderr':