glog: Fix coloring when scrolling

Due to the formatting placeholders sitting on the previous line, the
coloring of the topmost line disappeared when scrolling (as the escape
sequence scrolled away). This had the background that I wanted the code
that sets up the format string to be very readable and if possible very
close to the actual output. And since the colors have all different
lengths I decided to place them on the previous line to have them out of
the way.

Fix this by placing the placeholders on the same output line while still
maintaining a readable format string (code). This is done by joining the
array without placing newlines so that it can now have multiple elements
for one output line and formatting those as wished.
This commit is contained in:
2024-11-01 01:55:03 +01:00
parent ed4dac6f82
commit 8be1c63c18

View File

@@ -24,23 +24,23 @@ git rev-parse || return
# abbreviated commit hash (yellow), title and ref names
local formatshort='--pretty=format:%C(yellow)%h %Creset%s%C(auto)%d'
# Verbose format for the preview window on the right
# This array is stitched together with newlines later
local -a format=(
'--pretty=format:%C(yellow)' # newline created by this eaten by %-
'%-Commit: %H%C(auto)' # yellow commit hash
' %D%Cblue' # auto colored ref names (if any)
'Author: %aN <%aE>%Cred' # blue author mail
'AuthorDate: %ad%Cblue' # red author date
'Commit: %cN <%cE>%Cred' # blue commiter mail
'CommitDate: %cd%Cblue' # red commit date
'Signer: %GS%Cgreen' # signer name
'Key (%G?): %GK' # pgp key used to sign
'%Creset%C(bold)' # empty line
' %s%Creset' # bold white subject
'' # newline
'%-b' # body
'' # newline
'--pretty=format:'
'%C(yellow)' 'Commit: ' '%H' '%n' # commit hash
'%C(auto)' ' ' '%D' '%n' # ref names (if any)
'%C(blue)' 'Author: ' '%aN <%aE>' '%n' # author mail
'%C(red)' 'AuthorDate: ' '%ad' '%n' # author date
'%C(blue)' 'Commit: ' '%cN <%cE>' '%n' # commiter mail
'%C(red)' 'CommitDate: ' '%cd' '%n' # commit date
'%C(blue)' 'Signer: ' '%GS' '%n' # signer name
'%C(green)' 'Key (%G?): ' '%GK' '%n' # pgp key used to sign
'%n'
'%C(reset)%C(bold)' ' %s%C(reset)' '%n' # subject
'%n'
'%-b' # body
'%n'
)
format="${(j::)format}"
# Ignore the graph part at the beginning, then capture the commit hash and throw
# away the rest of the line.
@@ -56,7 +56,7 @@ EOT
fzf_preview[construct]="$REPLY"
read -r -d '' <<EOT
git show "${(j:%n:)format}" "$date" --color=always --patch-with-stat "\$out"
git show "$format" "$date" --color=always --patch-with-stat "\$out"
EOT
fzf_preview[patch]="$fzf_preview[construct] { $REPLY"
# Get file arguments after (and including) `--` and wrap each in double quotes
@@ -75,7 +75,7 @@ fzf_preview[patch]+="${pager:+ | }$pager; }"
fzf_preview[files_only]+="${pager:+ | }$pager; }"
read -r -d '' <<EOT
git show "${(j:%n:)format}" "$date" --color=always --stat "\$out"
git show "$format" "$date" --color=always --stat "\$out"
EOT
fzf_preview[stat]="$fzf_preview[construct] { $REPLY; }"