diff --git a/gitsync.sh b/gitsync.sh index c01a5ea8e..6ec1d3aaa 100755 --- a/gitsync.sh +++ b/gitsync.sh @@ -50,9 +50,7 @@ draw_bar() { local width=$2 local text="$3" - # Strip color codes for length calculation local clean_text=$(echo -ne "$text" | sed 's/\x1b\[[0-9;]*m//g') - [ ${#clean_text} -gt $width ] && clean_text="${clean_text:0:$width}" local filled=$(( percent * width / 100 )) @@ -97,21 +95,24 @@ run_deployment() { done wait "$pid" - # Fill bar to end of step echo -ne "\r$(draw_bar $step_percent_end $BAR_WIDTH "$step_name")$CLEAR_LINE" done # Final green completion bar final_text="Deployment Complete" - # Construct bar normally - bar=$(draw_bar 100 $BAR_WIDTH "$final_text") - # Replace the visible text in the middle with green text - clean_text_len=${#final_text} - start=$(( (BAR_WIDTH - clean_text_len) / 2 + 1 )) # +1 for the [ - end=$(( start + clean_text_len - 1 )) - colored_bar="${bar:0:start-1}${GREEN}${final_text}${RESET}${bar:end}" - echo -e "\r$colored_bar$CLEAR_LINE" -# echo "Log: $LOG_FILE" + final_bar=$(draw_bar 100 $BAR_WIDTH "$final_text") + + # Find start index of text inside brackets (exclude leading '[') + text_len=${#final_text} + bar_only=${final_bar:1:BAR_WIDTH} # strip leading '[' + start=$(( (BAR_WIDTH - text_len) / 2 )) + end=$(( start + text_len )) + + # Reconstruct bar with green text in place + green_bar="${final_bar:0:start+1}${GREEN}${final_text}${RESET}${final_bar:end+1}" + + echo -e "\r$green_bar$CLEAR_LINE" + #echo "Log: $LOG_FILE" } run_deployment