underline: Fix bugs with incorrect lengths

This commit is contained in:
Dylan Araps 2019-05-02 16:22:41 +03:00
parent ad16b5925c
commit 3f13df386c
1 changed files with 8 additions and 9 deletions

View File

@ -3939,13 +3939,10 @@ prin() {
string="${2:-$1}" string="${2:-$1}"
local subtitle_color="$info_color" local subtitle_color="$info_color"
fi fi
string="$(trim "${string//$'\e[0m'}")"
# Log length if it doesn't exist. string="$(trim "${string//$'\e[0m'}")"
if [[ -z "$length" ]]; then
length="$(strip_sequences "$string")" length="$(strip_sequences "$string")"
length="${#length}" length="${#length}"
fi
# Format the output. # Format the output.
string="${string/:/${reset}${colon_color}${separator:=:}${info_color}}" string="${string/:/${reset}${colon_color}${separator:=:}${info_color}}"
@ -3962,14 +3959,14 @@ prin() {
} }
get_underline() { get_underline() {
if [[ "$underline_enabled" == "on" ]]; then [[ "$underline_enabled" == "on" ]] && {
printf -v underline "%${length}s" printf -v underline "%${length}s"
printf '%b%b\n' "${text_padding:+\e[${text_padding}C}${zws}${underline_color}" \ printf '%b%b\n' "${text_padding:+\e[${text_padding}C}${zws}${underline_color}" \
"${underline// /$underline_char}${reset} " "${underline// /$underline_char}${reset} "
unset -v length }
fi
((++info_height)) ((++info_height))
length=
prin=1 prin=1
} }
@ -4001,6 +3998,8 @@ trim_quotes() {
strip_sequences() { strip_sequences() {
strip="${1//$'\e['3[0-9]m}" strip="${1//$'\e['3[0-9]m}"
strip="${strip//$'\e['[0-9]m}"
strip="${strip//\\e\[[0-9]m}"
strip="${strip//$'\e['38\;5\;[0-9]m}" strip="${strip//$'\e['38\;5\;[0-9]m}"
strip="${strip//$'\e['38\;5\;[0-9][0-9]m}" strip="${strip//$'\e['38\;5\;[0-9][0-9]m}"
strip="${strip//$'\e['38\;5\;[0-9][0-9][0-9]m}" strip="${strip//$'\e['38\;5\;[0-9][0-9][0-9]m}"