git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH] git-prompt: make colourization consistent

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 1, 2022, 18:07 UTC
Message-ID
<xmqq7d60tfyd.fsf@gitster.g>
In-Reply-To
<20220601134414.66825-1-joak-pet@online.no>
Joakim Petersen <joak-pet@online.no> writes:
Show 9 quoted lines
> The short upstream state indicator inherits the colour of the last short
> state indicator before it (if there is one), and the sparsity state
> indicator inherits this colour as well. Make the colourization of these
> state indicators consistent by clearing any colour before printing the
> short upstream state indicator, as this immediately follows the last
> coloured indicator.
>
> Signed-off-by: Joakim Petersen <joak-pet@online.no>
> ---
Show 11 quoted lines
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index 87b2b916c0..dfd6cef35f 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -286,6 +286,7 @@ __git_ps1_colorize_gitstring ()
>  	if [ -n "$u" ]; then
>  		u="$bad_color$u"
>  	fi
> +	p="$c_clear$p"
>  	r="$c_clear$r"
>  }
Hmph, am I correct to understand that the general flow of __git_ps1 is 
 (1) various pieces of information like $h, $w, $i, $s, $r, $b, $p,
     etc.  are declared "local" and values computed for them,
     either inside __git_ps1() itself, or by various helper
     functions it calls;
 (2) When GIT_PS1_SHOWCOLORHINTS is in effect, we may call the
     __git_ps1_colorize_gitstring helper (which is touched by the
     above hunk), that modifies these variables with color codes.
     Upon entry to this helper function, these variables prepared in
     (1) have no color effects.  Upon leaving, they do.
 (3) Finally, the PS1 is asseembled by concatenating these
     variables, whose text was prepared in (1) and then prefixed by
     color codes in (2), one of the earliest steps begins like so:
     local f="$h$w$i$s$u"
     local gitstring="$c$b${f:+$z$f}${sparse}$r$p"

In the final step of formulation, $p immediately follows $r in the resulting $PS1, and the existing code at the end of the (2) prefixes $c_clear before $r, and $r before such prefixing is free of coloring, so it is curious how this patch makes difference (other than emitting $c_clear one more time). Unless there is a use of $p that does not immediately follow $r, that is.

Thanks.
Previous: Joakim PetersenNext: Joakim Petersen
Message 4 of 43 in “git-prompt: make colourization consistent”
  1. git-prompt: make colourization consistentJoakim Petersen, Jun 1, 2022
  2. Ævar Arnfjörð BjarmasonJun 1, 2022
  3. Joakim PetersenJun 1, 2022
  4. Junio C HamanoJun 1, 2022
  5. Joakim PetersenJun 1, 2022
  6. Junio C HamanoJun 1, 2022
  7. git-prompt: make colourization consistentJoakim Petersen, Jun 2, 2022
  8. joak-pet@online.noJun 2, 2022
  9. Junio C HamanoJun 2, 2022
  10. Joakim PetersenJun 3, 2022
  11. git-prompt: make colourization consistentJoakim Petersen, Jun 3, 2022
  12. Junio C HamanoJun 3, 2022
  13. Joakim PetersenJun 3, 2022
  14. Joakim PetersenJun 3, 2022
  15. Justin DonnellyJun 3, 2022
  16. Junio C HamanoJun 3, 2022
  17. Joakim PetersenJun 4, 2022
  18. Junio C HamanoJun 6, 2022
  19. Junio C HamanoJun 3, 2022
  20. git-prompt: make colourization consistentJoakim Petersen, Jun 4, 2022
  21. Justin DonnellyJun 4, 2022
  22. Joakim PetersenJun 4, 2022
  23. git-prompt: make colourization consistentJoakim Petersen, Jun 4, 2022
  24. Bagas SanjayaJun 6, 2022
  25. Junio C HamanoJun 7, 2022
  26. Joakim PetersenJun 9, 2022
  27. Junio C HamanoJun 6, 2022
  28. Joakim PetersenJun 6, 2022
  29. Junio C HamanoJun 6, 2022
  30. Joakim PetersenJun 7, 2022
  31. git-prompt: make colourization consistentJoakim Petersen, Jun 6, 2022
  32. git-prompt: make colourization consistentJoakim Petersen, Jun 7, 2022
  33. Junio C HamanoJun 7, 2022
  34. Joakim PetersenJun 9, 2022
  35. SZEDER GáborJun 9, 2022
  36. Joakim PetersenJun 9, 2022
  37. Junio C HamanoJun 9, 2022
  38. SZEDER GáborJun 11, 2022
  39. git-prompt: make colouring consistentJoakim Petersen, Jun 9, 2022
  40. git-prompt: fix expansion of branch colour codesJoakim Petersen, Jun 9, 2022
  41. Junio C HamanoJun 10, 2022
  42. Joakim PetersenJun 10, 2022
  43. git-prompt: fix expansion of branch colour codesJoakim Petersen, Jun 10, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.