From 9573eee324b59d5ae3991654e0d5028e20b28242 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 28 Jan 2017 03:01:11 +1100 Subject: [PATCH] Prin: Fix underline not working --- neofetch | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index b2a60827..5e4f8929 100755 --- a/neofetch +++ b/neofetch @@ -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^}" }