How to use the templater without color (even when ui has color)
Martin von Zweigbergk
martinvonz at google.com
Mon Nov 16 18:24:16 UTC 2020
That's not a solution I would have thought of. Thanks! I've sent a fix for
`hg split` in https://phab.mercurial-scm.org/D9322. I'll work on one for
histedit now. Hopefully testing it is not too annoying.
On Sat, Nov 14, 2020 at 1:19 AM Yuya Nishihara <yuya at tcha.org> wrote:
> On Fri, 13 Nov 2020 09:20:24 -0800, Martin von Zweigbergk wrote:
> > I recently added support for some templated output in `hg split` (
> > https://phab.mercurial-scm.org/D9255). I didn't realize when I wrote the
> > patch that it was producing the templated output for use in a commit
> > message template. The effect was that color codes ended up in the commit
> > message template. How should I fix it? The following seems to fix it, but
> > maybe there's a cleaner way?
> >
> > ```
> > diff --git a/hgext/split.py b/hgext/split.py
> > --- a/hgext/split.py
> > +++ b/hgext/split.py
> > @@ -142,9 +142,13 @@ def dosplit(ui, repo, tr, ctx, opts):
> > header = _(
> > b'HG: Splitting %s. So far it has been split into:\n'
> > ) % short(ctx.node())
> > - for c in committed:
> > - summary = cmdutil.format_changeset_summary(ui, c,
> b'split')
> > - header += _(b'HG: - %s\n') % summary
> > + from mercurial import color
> > + with ui.configoverride({(b'ui', b'color'): b"no"},
> b'split'):
> > + color.setup(ui)
> > + for c in committed:
> > + summary = cmdutil.format_changeset_summary(ui, c,
> > b'split')
> > + header += _(b'HG: - %s\n') % summary
> > + color.setup(ui)
>
> If we don't want to use separate templates for colored/plain outputs, we'll
> need to disable the label() function. I think the easiest option is to
> remove label() calls by alias:
>
> --config 'templatealias.label(l, x)=x'
>
> Maybe local aliases can be inserted at formatter.maketemplater().
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20201116/3464eeac/attachment-0002.html>
More information about the Mercurial-devel
mailing list