git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Joakim Petersen <joak-pet@online.no>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Justin Donnelly" <justinrdonnelly@gmail.com>
Subject: Re: [PATCH v3] git-prompt: make colourization consistent
Date: Fri, 3 Jun 2022 19:23:25 +0200	[thread overview]
Message-ID: <7d391d82-b15e-4a31-5207-c4037fec0bf9@online.no> (raw)
In-Reply-To: <xmqqy1ydhfcc.fsf@gitster.g>

On 03/06/2022 18:38, Junio C Hamano wrote:
> This is not a new issue, but seeing this:
> 
>   	if [ $detached = no ]; then
>   		branch_color="$ok_color"
>   	else
>   		branch_color="$bad_color"
>   	fi
>   	c="$branch_color$c"
>   
>   	z="$c_clear$z"
>   	if [ "$w" = "*" ]; then
>   		w="$bad_color$w"
>   	fi
>   	if [ -n "$i" ]; then
>   		i="$ok_color$i"
>   	fi
>   	if [ -n "$s" ]; then
>   		s="$flags_color$s"
>   	fi
>   	if [ -n "$u" ]; then
>   		u="$bad_color$u"
>   	fi
> +	if [ -n "$p" ]; then
> +		p="$c_clear$p"
> +	fi
> +	if [ -n "$sparse" ]; then
> +		sparse="$c_clear$sparse"
> +	fi
>   	r="$c_clear$r"
>   }
> 
> it makes me wonder if the more forward looking and future-proof way
> that is resistant to any future and random reshuffling like what
> 0ec7c23c (git-prompt: make upstream state indicator location
> consistent, 2022-02-27) did would be to make it a rule to maintain
> that there is no coloring by default, and when any of these tokens
> like w, i, s, ... are not empty, enclose them inside "color-on" and
> "color-off" sequence.
> 
> For example,
> 
>   	if [ "$w" = "*" ]; then
>   		w="$bad_color$w"
>   	fi
> 
> would mean $w, when it is "*", would cause gitstring to contain an
> asterisk that is painted in $bad_color, but ALSO causes whatever
> that happens to come AFTER $w in gitstring to be painted in the same
> color UNLESS it tries to protect itself.  Right now, $w may be
> immediately followed by $i, and $i does protect itself by prefixing
> with $ok_color, but if $i is empty, $w's coloring will extend to $s.
> 
> So, if we did this instead:
> 
> - 	z="$c_clear$z"
>   	if [ "$w" = "*" ]; then
> - 		w="$bad_color$w"
> + 		w="$bad_color$w$c_clear"
>   	fi
> 
> and make similar changes to everything else we see above, we
> probably can lose the ones that prefix with $c_clear, because each
> token that paints itself in unusual color is now responsible for
> returning the terminal state to normal with the $c_clear sequence
> after it is done with it.  We do not have to special case sparse, p,
> or r in this helper function at all if we go that route, no?
> 
> If the helper were written that way, then reshuffling the order of
> the tokens done in 0ec7c23c (git-prompt: make upstream state
> indicator location consistent, 2022-02-27) wouldn't have made the
> patch under discussion necessary at all, which is what I see is
> valuable from the "maintainability" point of view.
> 

That does seem like a much better idea for maintainability, I can
change the patch to do this instead. I have one question, though: the
sequence $c$b (bare state and branch name) is a special case, where
they're intended to have the same colour, should I wrap both in colour
set, colour clear, or only clear after $b? The former requires rewriting
the tests or changing $gitstring to not include $c when $c is empty,
while the latter keeps the tests unchanged, but may pose a problem if
"BARE:" should at any point not appear immediately before the branch
name.

  reply	other threads:[~2022-06-03 17:23 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01 13:44 [RFC PATCH] git-prompt: make colourization consistent Joakim Petersen
2022-06-01 14:47 ` Ævar Arnfjörð Bjarmason
2022-06-01 18:26   ` Joakim Petersen
2022-06-01 18:07 ` Junio C Hamano
2022-06-01 18:32   ` Joakim Petersen
2022-06-01 20:45     ` Junio C Hamano
2022-06-02 14:59 ` [PATCH v2] " Joakim Petersen
2022-06-02 21:56   ` joak-pet
2022-06-02 22:49   ` Junio C Hamano
2022-06-03 13:55     ` Joakim Petersen
2022-06-03 14:25   ` [PATCH v3] " Joakim Petersen
2022-06-03 16:38     ` Junio C Hamano
2022-06-03 17:23       ` Joakim Petersen [this message]
2022-06-03 18:51         ` Joakim Petersen
2022-06-03 19:43           ` Justin Donnelly
2022-06-03 21:16             ` Junio C Hamano
2022-06-04  9:42               ` Joakim Petersen
2022-06-06 16:13                 ` Junio C Hamano
2022-06-03 20:50         ` Junio C Hamano
2022-06-04 16:13     ` [PATCH v4] " Joakim Petersen
2022-06-04 17:30       ` Justin Donnelly
2022-06-04 19:18         ` Joakim Petersen
2022-06-04 19:26       ` [PATCH v5] " Joakim Petersen
2022-06-06  7:23         ` Bagas Sanjaya
2022-06-07 16:04           ` Junio C Hamano
2022-06-09 11:25             ` Joakim Petersen
2022-06-06 16:29         ` Junio C Hamano
2022-06-06 17:31           ` Joakim Petersen
2022-06-06 17:41             ` Junio C Hamano
2022-06-07 11:49               ` Joakim Petersen
2022-06-06 17:50         ` [PATCH v6] " Joakim Petersen
2022-06-07 11:50           ` [PATCH v7] " Joakim Petersen
2022-06-07 16:22             ` Junio C Hamano
2022-06-09 11:16               ` Joakim Petersen
2022-06-09  9:03             ` SZEDER Gábor
2022-06-09 11:13               ` Joakim Petersen
2022-06-09 18:29                 ` Junio C Hamano
2022-06-11  9:01                   ` SZEDER Gábor
2022-06-09 11:44             ` [PATCH v8] git-prompt: make colouring consistent Joakim Petersen
2022-06-09 20:44             ` [PATCH] git-prompt: fix expansion of branch colour codes Joakim Petersen
2022-06-10  0:05               ` Junio C Hamano
2022-06-10  0:33                 ` Joakim Petersen
2022-06-10  0:47               ` [PATCH v2] " Joakim Petersen

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=7d391d82-b15e-4a31-5207-c4037fec0bf9@online.no \
    --to=joak-pet@online.no \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=justinrdonnelly@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).