From 3271d9609769d04b9d11b5e378047401535f9630 Mon Sep 17 00:00:00 2001 From: Matias Barcenas Date: Tue, 26 Dec 2017 20:47:24 -0600 Subject: [PATCH] Fixed an auto-size bug caused by remaining space. This issue was noticable when auto-size failed to fit all spaces to tokens. Auto-sizing will no longer ignore remaining space and will auto-fill it. --- lib/FormatUtils.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/FormatUtils.sh b/lib/FormatUtils.sh index f80940f..921f97c 100755 --- a/lib/FormatUtils.sh +++ b/lib/FormatUtils.sh @@ -163,10 +163,18 @@ function format_calculate_autosize_length() { # This function replaces dynamics' asterisks with their length, in format. # Parameters: $1 - format [$2 - dynamics length [$3 - dynamics count]] -# Note that this does not yet support multiple lines (multiple \n). +# Warning: Strings containing '\n' result in undefined behavior (not supported). +# Warning: Strings containing [0-9]+.* result in undefined behavior. +# Notice: Single asterisks are auto-sized, doubles are replaced "**" -> "*". function format_apply_autosize() { format_calculate_autosize_length "${@}" # Pass all arguments on. - FormatApplyAutosize=$(echo "$1" | sed -r 's/\*\.\*/'"$FormatCalculateAutosizeLength"'.'"$FormatCalculateAutosizeLength"'/g; s/(^|[^*])\*([^*]|$)/\1'"$FormatCalculateAutosizeLength"'\2/g; s/\*\*/*/g') + FormatApplyAutosize=$1 + let format_apply_autosize_overcount=$FormatCalculateDynamicsLength%$FormatCalculateDynamicsCount + if [ $format_apply_autosize_overcount -gt 0 ]; then # If we've got left-over, fill it left-to-right. + let format_apply_autosize_oversize=$FormatCalculateAutosizeLength+1 + FormatApplyAutosize=$(echo "$FormatApplyAutosize" | sed -r 's/(^|[^*])\*(\.\*|[^*]|$)/\1'$format_apply_autosize_oversize'\2/'$format_apply_autosize_overcount'; s/([0-9]+\.)\*/\1'$format_apply_autosize_oversize'/'$format_apply_autosize_overcount) + fi + FormatApplyAutosize=$(echo "$FormatApplyAutosize" | sed -r 's/\*\.\*/'$FormatCalculateAutosizeLength'.'$FormatCalculateAutosizeLength'/g; s/(^|[^*])\*([^*]|$)/\1'$FormatCalculateAutosizeLength'\2/g; s/\*\*/*/g') } # This function centers literal text.