git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Hari Lubovac <hlubovac@gmail.com>
Cc: git <git@vger.kernel.org>
Subject: Re: MINOR: log-format "%C" & "%+" log
Date: Wed, 22 Aug 2018 15:07:18 -0400	[thread overview]
Message-ID: <20180822190718.GA19730@sigill.intra.peff.net> (raw)
In-Reply-To: <CAFLu24kbCJu74tgfRDR=xPZ3pkbau9R6jmqPbFKR=ZnWOvbCvQ@mail.gmail.com>

On Wed, Aug 22, 2018 at 09:46:08AM -0700, Hari Lubovac wrote:

> I don't know where else to report this. It relates to the "log"
> command with "--pretty:format" argument.
> 
> It appears to me that "%C" format argument combined with "%+" or "%-"
> results in no color applied.
> 
> For example, I'd expect the last part of the output line ("%+D") to be
> colored red (it does when the "+" is removed):
> 
> git log --pretty="format:%C(Yellow)%t %C(reset)%ad
> %C(Cyan)%<(6,trunc)%an %C(reset)%s %C(Red)%+D" --date="format:%m/%d"
> 
> This info is taken from https://git-scm.com/docs/pretty-formats: "If
> you add a + (plus sign) after '%' of a placeholder..."

Hmm. I think this is actually due to the way the pager displays colors.

Try this:

  git --no-pager log -1 --format='foo%C(red)%+an'

I see the committer name on its own line in read, as expected. Now try
the same thing with a pager:

  git log -1 --format='foo%C(red)%+an'

I see no color.

The actual output sequence is (<red>, <newline>, <author>). So
presumably what is happening is that the pager does not let color from
the previous line impact to the next line.

Unfortunately I don't know if there's an easy workaround. What you
really want is to apply the "+" magic to a whole section of the string.
You can do that with git-for-each-ref's format, like:

  %(if)%D%(then)%n%C(red)%D%(end)

but the two formats are not (yet) unified. There's interest in doing
that, and an Outreachy intern worked on it over the winter, but there's
still a long way to go.

-Peff

      reply	other threads:[~2018-08-22 19:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-22 16:46 MINOR: log-format "%C" & "%+" log Hari Lubovac
2018-08-22 19:07 ` Jeff King [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180822190718.GA19730@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=hlubovac@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).