Prin: Fix underline not working

This commit is contained in:
Dylan Araps 2017-01-28 03:01:11 +11:00
parent c4869f5e50
commit 9573eee324
1 changed files with 19 additions and 5 deletions

View File

@ -2541,11 +2541,9 @@ info() {
output="$(trim "${!2:-${!1}}")"
if [[ "$2" && "${output// }" ]]; then
length="$((${#1} + ${#output} + 2))"
prin "$1" "$output"
elif [[ "${output// }" ]]; then
[[ -z "$length" ]] && length="${#output}"
prin "$output"
else
@ -2558,14 +2556,20 @@ info() {
prin() {
# If $2 doesn't exist we format $1 as info.
if [[ "$(trim "$1")" && "$2" ]]; then
string="${1//$'\033[0m'}${2:+: $2}"
string="${1}${2:+: $2}"
else
string="${2:-$1}"
local subtitle_color="$info_color"
fi
string="$(trim "${string//$'\033[0m'}")"
# Log length if it doesn't exist.
if [[ -z "$length" ]]; then
length="$(strip_sequences "$string")"
length="${#length}"
fi
# Format the output.
string="$(trim "$string")"
string="${string/:/${reset}${colon_color}:${info_color}}"
string="${subtitle_color}${bold}${string}"
@ -2582,9 +2586,10 @@ prin() {
get_underline() {
if [[ "$underline_enabled" == "on" ]]; then
printf -v underline "%${length}s"
underline="${underline_color}${underline// /$underline_char}"
printf "%b\n" "${text_padding:+\033[${text_padding}C}${zws}${underline// /$underline_char}${reset} "
unset -v length
fi
prin=1
}
get_line_break() {
@ -2633,6 +2638,15 @@ trim_quotes() {
printf "%s" "$trim_output"
}
strip_sequences() {
strip="${1//$'\033['3?m}"
strip="${strip//$'\033['38\;5\;[0-9]m}"
strip="${strip//$'\033['38\;5\;[0-9][0-9]m}"
strip="${strip//$'\033['38\;5\;[0-9][0-9][0-9]m}"
printf "%s\n" "$strip"
}
uppercase() {
((bash_version >= 4)) && printf "%s" "${1^}"
}