Skip to content

Commit 657aea9

Browse files
committed
v8.11
- DietPi-Banner | Further performance enhancements
1 parent 89d6c4f commit 657aea9

File tree

1 file changed

+25
-36
lines changed

1 file changed

+25
-36
lines changed

dietpi/func/dietpi-banner

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,61 +76,50 @@
7676
'\e[91m' # Red | Update notifications
7777
)
7878

79-
# Parse the above colour strings and use them to generate an expression to match them via bash substitution
80-
__make_strip_color(){
81-
local tmp="${aCOLOUR[*]} $COLOUR_RESET" # convert array to string
82-
tmp="+(${tmp// /|})" # convert list into OR expression
83-
tmp=${tmp//\\e/\\\\\\e} # ensure '\e' exists
84-
tmp=${tmp//\[/\\[} # ensure '\[' exists
85-
echo "$tmp"
86-
}
87-
shopt -s extglob # globally enable multiple pattern matching
88-
COLOUR_STRIP=$(__make_strip_color)
89-
9079
# Load settings here, to have chosen ${aCOLOUR[0]} applied to below strings
9180
# shellcheck disable=SC1090
9281
[[ -f $FP_SAVEFILE ]] && . "$FP_SAVEFILE"
9382

9483
TERM_WIDTH=$(tput cols)
95-
96-
GREEN_LINE_FILLER=$(printf -- "─%.0s" $(seq 1 $(( $TERM_WIDTH - 2 ))))
97-
GREEN_LINE=" ${aCOLOUR[0]}${GREEN_LINE_FILLER}$COLOUR_RESET"
84+
printf -v GREEN_LINE "%$(( $TERM_WIDTH - 2 ))s" # Separator line with 1 space left and right respectively
85+
GREEN_LINE=" ${aCOLOUR[0]}${GREEN_LINE//?/─}$COLOUR_RESET"
9886
GREEN_BULLET=" ${aCOLOUR[0]}-$COLOUR_RESET"
9987
GREEN_SEPARATOR="${aCOLOUR[0]}:$COLOUR_RESET"
10088

10189
# Print a banner line split into title and description with word-wrapping
90+
shopt -s extglob # globally extended globbing for "*(pattern)" syntax
10291
Print_Line()
10392
{
104-
local title=$1 # Bold part before ":"
93+
local title=$1 # Bold part before including ":"
10594
local descp=$2 # Normal part after ":"
10695

10796
if (( ${aENABLED[16]} == 1 ))
10897
then
109-
# Strip invisible colour codes in order to accurately measure the visual length of a sentence.
110-
local stripped_title=${title//$COLOUR_STRIP}
111-
local stripped_descp=${descp//$COLOUR_STRIP}
98+
# Strip control codes to accurately measure visual length
99+
local stripped_title=${title//\\e[[0-9]*([;0-9])m}
100+
local stripped_descp=${descp//\\e[[0-9]*([;0-9])m}
112101
local title_len=${#stripped_title}
113102
local descp_len=${#stripped_descp}
114103

115-
# Sometimes the title is long, so a sanity check is performed to fold the title
116-
# if it exceeds the window size. Because of the hyphen it receives 3 spaces padding.
104+
# Wrap title if required
117105
if (( $title_len >= $TERM_WIDTH ))
118106
then
119107
title=$(echo "$stripped_title" | fold -s -w "$TERM_WIDTH")
120-
title=${title//$'\n'/$'\n' }
108+
title=${title//$'\n'/$'\n' } # Add 3 spaces padding for hyphen
121109
title="${aCOLOUR[1]}$title$COLOUR_RESET"
122110
# Recalculate the title length based on the last line with padding
123-
title_len=$(( (($title_len + 3) % $TERM_WIDTH) + 3 ))
111+
title_len=$(( ($title_len + 3) % $TERM_WIDTH + 3 ))
124112
fi
125113

114+
# Obtain remaining length for description starting 1 space after title
126115
local avail_len=$(( $TERM_WIDTH - $title_len - 1))
127-
local left_pad=$(printf -- ' %.0s' $(seq 0 "$title_len"))
128116

129-
# The description is typically very long, and is folded from the second line
130-
# onwards into the remaining available space, with left padding.
117+
# Wrap description if required
131118
if (( $descp_len >= $avail_len ))
132119
then
133120
descp=$(echo "$stripped_descp" | fold -s -w "$avail_len")
121+
local left_pad
122+
printf -v left_pad "%$(( $title_len + 1 ))s"
134123
descp=${descp//$'\n'/$'\n'$left_pad}
135124
fi
136125
fi
@@ -241,17 +230,17 @@
241230

242231
Print_Credits(){
243232

244-
Print_Line " ${aCOLOUR[2]}DietPi Team :" "https://github.com/MichaIng/DietPi#the-dietpi-project-team"
233+
Print_Line " ${aCOLOUR[2]}DietPi Team :" 'https://github.com/MichaIng/DietPi#the-dietpi-project-team'
245234

246235
if [[ -f '/boot/dietpi/.prep_info' ]]; then
247236
local info=$(mawk 'NR==1 {sub(/^0$/,"DietPi Core Team");a=$0} NR==2 {print ""a" (pre-image: "$0")"}' /boot/dietpi/.prep_info)
248-
Print_Line " Image by :" "$info"
237+
Print_Line ' Image by :' "$info"
249238
fi
250239

251-
Print_Line " Patreon Legends :" "Camry2731, Chris Gelatt"
252-
Print_Line " Website :" "https://dietpi.com/ | https://twitter.com/DietPi_"
253-
Print_Line " Contribute :" "https://dietpi.com/contribute.html"
254-
Print_Line " Web Hosting by :" "https://myvirtualserver.com$COLOUR_RESET\n"
240+
Print_Line ' Patreon Legends :' 'Camry2731, Chris Gelatt'
241+
Print_Line ' Website :' 'https://dietpi.com/ | https://twitter.com/DietPi_'
242+
Print_Line ' Contribute :' 'https://dietpi.com/contribute.html'
243+
Print_Line ' Web Hosting by :' "https://myvirtualserver.com$COLOUR_RESET\n"
255244

256245
}
257246

@@ -281,11 +270,11 @@
281270

282271
Print_Useful_Commands(){
283272

284-
Print_Line " ${aCOLOUR[1]}dietpi-launcher$COLOUR_RESET $GREEN_SEPARATOR" "All the DietPi programs in one place"
285-
Print_Line " ${aCOLOUR[1]}dietpi-config$COLOUR_RESET $GREEN_SEPARATOR" "Feature rich configuration tool for your device"
286-
Print_Line " ${aCOLOUR[1]}dietpi-software$COLOUR_RESET $GREEN_SEPARATOR" "Select optimised software for installation"
287-
Print_Line " ${aCOLOUR[1]}htop$COLOUR_RESET $GREEN_SEPARATOR" "Resource monitor"
288-
Print_Line " ${aCOLOUR[1]}cpu$COLOUR_RESET $GREEN_SEPARATOR" "Shows CPU information and stats\n"
273+
Print_Line " ${aCOLOUR[1]}dietpi-launcher$COLOUR_RESET $GREEN_SEPARATOR" 'All the DietPi programs in one place'
274+
Print_Line " ${aCOLOUR[1]}dietpi-config$COLOUR_RESET $GREEN_SEPARATOR" 'Feature rich configuration tool for your device'
275+
Print_Line " ${aCOLOUR[1]}dietpi-software$COLOUR_RESET $GREEN_SEPARATOR" 'Select optimised software for installation'
276+
Print_Line " ${aCOLOUR[1]}htop$COLOUR_RESET $GREEN_SEPARATOR" 'Resource monitor'
277+
Print_Line " ${aCOLOUR[1]}cpu$COLOUR_RESET $GREEN_SEPARATOR" 'Shows CPU information and stats\n'
289278

290279
}
291280

0 commit comments

Comments
 (0)