fix columns computation

This commit is contained in:
Johann Dreo 2023-07-24 14:18:49 +02:00
commit 317fb62f36

View file

@ -9,8 +9,8 @@ _gitcrux_centered() {
raw_text="$ret" raw_text="$ret"
if (( ${#raw_text} > width )); then if (( ${#raw_text} > width )); then
# gitcrux_centered="${text:0:width-1}…" gitcrux_centered="${text:0:width-1}…"
gitcrux_centered="$text" # gitcrux_centered="$text"
return 2 return 2
elif (( ${#raw_text} == width )); then elif (( ${#raw_text} == width )); then
gitcrux_centered="$text" gitcrux_centered="$text"
@ -52,9 +52,11 @@ _gitcrux_arrow() {
span=$((to-from-${#start}-${#end})) span=$((to-from-${#start}-${#end}))
if (( from > ${#in} || to > ${#in} )); then if (( from > ${#in} || to > ${#in} )); then
gitcrux_arrow="[bad arrow indexing]"
return 2 return 2
else else
if (( ${#text} > span )); then if (( ${#text} > span )); then
gitcrux_arrow="[arrow text too large]"
return 3 return 3
fi fi
fi fi
@ -150,16 +152,17 @@ _gitcrux_VCS_header() {
fi fi
# COLUMNS # COLUMNS
GITCRUX_COL_WIDTH=${GITCRUX_MIN_COL_WIDTH}
if [[ "$GITCRUX_COL_DYNAMIC" ]]; then if [[ "$GITCRUX_COL_DYNAMIC" ]]; then
for col in "${head_remote}" "${head_repo}" "${head_stage}" "${head_branch}" "${head_stash}"; do for col in "${head_remote}" "${head_repo}" "${head_stage}" "${head_branch}" "${head_stash}"; do
if (( ${#col} > GITCRUX_COL_WIDTH )); then
__lp_strip_escapes "${col}" __lp_strip_escapes "${col}"
if (( ${#ret} > GITCRUX_COL_WIDTH )); then
GITCRUX_COL_WIDTH="${#ret}" GITCRUX_COL_WIDTH="${#ret}"
fi fi
done done
fi
# At least some spacing. # At least some spacing.
GITCRUX_COL_WIDTH=$((GITCRUX_COL_WIDTH+2)) GITCRUX_COL_WIDTH=$((GITCRUX_COL_WIDTH+2))
fi
gitcrux_VCS_header="" gitcrux_VCS_header=""
_GITCRUX_HEADER_LINE="" _GITCRUX_HEADER_LINE=""
@ -431,9 +434,10 @@ _lp_gitcrux_theme_activate() {
GITCRUX_COLOR_EXPLANATION=${GITCRUX_COLOR_EXPLANATION:-"28 -1 0"} GITCRUX_COLOR_EXPLANATION=${GITCRUX_COLOR_EXPLANATION:-"28 -1 0"}
# Width of a single column. # Width of a single column.
GITCRUX_COL_WIDTH=${GITCRUX_COL_WIDTH:-0} local longest="< commit <"
GITCRUX_MIN_COL_WIDTH=${GITCRUX_MIN_COL_WIDTH:-${#longest}}
# Increase column width if at least one of the column text is larger than GITCRUX_COL_WIDTH. # Increase column width if at least one of the column text is larger than GITCRUX_MIN_COL_WIDTH.
GITCRUX_COL_DYNAMIC=${GITCRUX_COL_DYNAMIC:-1} GITCRUX_COL_DYNAMIC=${GITCRUX_COL_DYNAMIC:-1}
# Show a sentence explaining why the hint is shown. # Show a sentence explaining why the hint is shown.