|
76 | 76 | '\e[91m' # Red | Update notifications
|
77 | 77 | )
|
78 | 78 |
|
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 |
| - |
90 | 79 | # Load settings here, to have chosen ${aCOLOUR[0]} applied to below strings
|
91 | 80 | # shellcheck disable=SC1090
|
92 | 81 | [[ -f $FP_SAVEFILE ]] && . "$FP_SAVEFILE"
|
93 | 82 |
|
94 | 83 | 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" |
98 | 86 | GREEN_BULLET=" ${aCOLOUR[0]}-$COLOUR_RESET"
|
99 | 87 | GREEN_SEPARATOR="${aCOLOUR[0]}:$COLOUR_RESET"
|
100 | 88 |
|
101 | 89 | # Print a banner line split into title and description with word-wrapping
|
| 90 | + shopt -s extglob # globally extended globbing for "*(pattern)" syntax |
102 | 91 | Print_Line()
|
103 | 92 | {
|
104 |
| - local title=$1 # Bold part before ":" |
| 93 | + local title=$1 # Bold part before including ":" |
105 | 94 | local descp=$2 # Normal part after ":"
|
106 | 95 |
|
107 | 96 | if (( ${aENABLED[16]} == 1 ))
|
108 | 97 | 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} |
112 | 101 | local title_len=${#stripped_title}
|
113 | 102 | local descp_len=${#stripped_descp}
|
114 | 103 |
|
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 |
117 | 105 | if (( $title_len >= $TERM_WIDTH ))
|
118 | 106 | then
|
119 | 107 | 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 |
121 | 109 | title="${aCOLOUR[1]}$title$COLOUR_RESET"
|
122 | 110 | # 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 )) |
124 | 112 | fi
|
125 | 113 |
|
| 114 | + # Obtain remaining length for description starting 1 space after title |
126 | 115 | local avail_len=$(( $TERM_WIDTH - $title_len - 1))
|
127 |
| - local left_pad=$(printf -- ' %.0s' $(seq 0 "$title_len")) |
128 | 116 |
|
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 |
131 | 118 | if (( $descp_len >= $avail_len ))
|
132 | 119 | then
|
133 | 120 | descp=$(echo "$stripped_descp" | fold -s -w "$avail_len")
|
| 121 | + local left_pad |
| 122 | + printf -v left_pad "%$(( $title_len + 1 ))s" |
134 | 123 | descp=${descp//$'\n'/$'\n'$left_pad}
|
135 | 124 | fi
|
136 | 125 | fi
|
|
241 | 230 |
|
242 | 231 | Print_Credits(){
|
243 | 232 |
|
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' |
245 | 234 |
|
246 | 235 | if [[ -f '/boot/dietpi/.prep_info' ]]; then
|
247 | 236 | 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" |
249 | 238 | fi
|
250 | 239 |
|
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" |
255 | 244 |
|
256 | 245 | }
|
257 | 246 |
|
|
281 | 270 |
|
282 | 271 | Print_Useful_Commands(){
|
283 | 272 |
|
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' |
289 | 278 |
|
290 | 279 | }
|
291 | 280 |
|
|
0 commit comments