Skip to content

Commit

Permalink
v8.11
Browse files Browse the repository at this point in the history
- DietPi-Banner | Further performance enhancements
  • Loading branch information
MichaIng committed Jan 31, 2023
1 parent e1f1480 commit 97a87a7
Showing 1 changed file with 25 additions and 36 deletions.
61 changes: 25 additions & 36 deletions dietpi/func/dietpi-banner
Original file line number Diff line number Diff line change
Expand Up @@ -76,61 +76,50 @@
'\e[91m' # Red | Update notifications
)

# Parse the above colour strings and use them to generate an expression to match them via bash substitution
__make_strip_color(){
local tmp="${aCOLOUR[*]} $COLOUR_RESET" # convert array to string
tmp="+(${tmp// /|})" # convert list into OR expression
tmp=${tmp//\\e/\\\\\\e} # ensure '\e' exists
tmp=${tmp//\[/\\[} # ensure '\[' exists
echo "$tmp"
}
shopt -s extglob # globally enable multiple pattern matching
COLOUR_STRIP=$(__make_strip_color)

# Load settings here, to have chosen ${aCOLOUR[0]} applied to below strings
# shellcheck disable=SC1090
[[ -f $FP_SAVEFILE ]] && . "$FP_SAVEFILE"

TERM_WIDTH=$(tput cols)

GREEN_LINE_FILLER=$(printf -- "─%.0s" $(seq 1 $(( $TERM_WIDTH - 2 ))))
GREEN_LINE=" ${aCOLOUR[0]}${GREEN_LINE_FILLER}$COLOUR_RESET"
printf -v GREEN_LINE "%$(( $TERM_WIDTH - 2 ))s" # Separator line with 1 space left and right respectively
GREEN_LINE=" ${aCOLOUR[0]}${GREEN_LINE//?/─}$COLOUR_RESET"
GREEN_BULLET=" ${aCOLOUR[0]}-$COLOUR_RESET"
GREEN_SEPARATOR="${aCOLOUR[0]}:$COLOUR_RESET"

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

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

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

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

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

Print_Credits(){

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

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

Print_Line " Patreon Legends :" "Camry2731, Chris Gelatt"
Print_Line " Website :" "https://dietpi.com/ | https://twitter.com/DietPi_"
Print_Line " Contribute :" "https://dietpi.com/contribute.html"
Print_Line " Web Hosting by :" "https://myvirtualserver.com$COLOUR_RESET\n"
Print_Line ' Patreon Legends :' 'Camry2731, Chris Gelatt'
Print_Line ' Website :' 'https://dietpi.com/ | https://twitter.com/DietPi_'
Print_Line ' Contribute :' 'https://dietpi.com/contribute.html'
Print_Line ' Web Hosting by :' "https://myvirtualserver.com$COLOUR_RESET\n"

}

Expand Down Expand Up @@ -281,11 +270,11 @@

Print_Useful_Commands(){

Print_Line " ${aCOLOUR[1]}dietpi-launcher$COLOUR_RESET $GREEN_SEPARATOR" "All the DietPi programs in one place"
Print_Line " ${aCOLOUR[1]}dietpi-config$COLOUR_RESET $GREEN_SEPARATOR" "Feature rich configuration tool for your device"
Print_Line " ${aCOLOUR[1]}dietpi-software$COLOUR_RESET $GREEN_SEPARATOR" "Select optimised software for installation"
Print_Line " ${aCOLOUR[1]}htop$COLOUR_RESET $GREEN_SEPARATOR" "Resource monitor"
Print_Line " ${aCOLOUR[1]}cpu$COLOUR_RESET $GREEN_SEPARATOR" "Shows CPU information and stats\n"
Print_Line " ${aCOLOUR[1]}dietpi-launcher$COLOUR_RESET $GREEN_SEPARATOR" 'All the DietPi programs in one place'
Print_Line " ${aCOLOUR[1]}dietpi-config$COLOUR_RESET $GREEN_SEPARATOR" 'Feature rich configuration tool for your device'
Print_Line " ${aCOLOUR[1]}dietpi-software$COLOUR_RESET $GREEN_SEPARATOR" 'Select optimised software for installation'
Print_Line " ${aCOLOUR[1]}htop$COLOUR_RESET $GREEN_SEPARATOR" 'Resource monitor'
Print_Line " ${aCOLOUR[1]}cpu$COLOUR_RESET $GREEN_SEPARATOR" 'Shows CPU information and stats\n'

}

Expand Down

0 comments on commit 97a87a7

Please sign in to comment.