Implemented FormatUtils & used for startup banner.
The new horizontal utility utilizes the * token for centering. * Every field with the token %*s will autofill the remaining space. * Field tokens may be any valid format specifier, plus the asterisk. * > Example: printf "%*s %.*s %*d" "col1" "col2" "3.0" (notice asterisk) * > Example: printf "%*b %s" "\e[1;33mThis is red text\e[0m" "this is not" Use the new utilities to center the startup banner and other messages.
This commit is contained in:
parent
15494058aa
commit
ad89264442
61
fluxion.sh
61
fluxion.sh
|
@ -25,14 +25,14 @@ export FLUXIONOutputDevice=$([ $FLUXIONDebug ] && echo "/dev/stdout" || echo "/d
|
||||||
FLUXIONHoldXterm=$([ $FLUXIONDebug ] && echo "-hold" || echo "")
|
FLUXIONHoldXterm=$([ $FLUXIONDebug ] && echo "-hold" || echo "")
|
||||||
|
|
||||||
################################# < Shell Color Codes > ################################
|
################################# < Shell Color Codes > ################################
|
||||||
CRed="\033[1;31m"
|
CRed="\e[1;31m"
|
||||||
CGrn="\033[1;32m"
|
CGrn="\e[1;32m"
|
||||||
CYel="\033[1;33m"
|
CYel="\e[1;33m"
|
||||||
CBlu="\033[1;34m"
|
CBlu="\e[1;34m"
|
||||||
CPrp="\033[5;35m"
|
CPrp="\e[5;35m"
|
||||||
CCyn="\033[5;36m"
|
CCyn="\e[5;36m"
|
||||||
CGry="\033[0;37m"
|
CGry="\e[0;37m"
|
||||||
CWht="\033[1;37m"
|
CWht="\e[1;37m"
|
||||||
CClr="\e[0m"
|
CClr="\e[0m"
|
||||||
|
|
||||||
################################ < FLUXION Parameters > ################################
|
################################ < FLUXION Parameters > ################################
|
||||||
|
@ -41,6 +41,7 @@ FLUXIONVLine="$CRed[$CYel*$CRed]$CClr"
|
||||||
|
|
||||||
################################# < Library Includes > #################################
|
################################# < Library Includes > #################################
|
||||||
source lib/SandboxUtils.sh
|
source lib/SandboxUtils.sh
|
||||||
|
source lib/FormatUtils.sh
|
||||||
source lib/IOUtils.sh
|
source lib/IOUtils.sh
|
||||||
source lib/HashUtils.sh
|
source lib/HashUtils.sh
|
||||||
|
|
||||||
|
@ -244,19 +245,23 @@ function check_dependencies() {
|
||||||
|
|
||||||
for CLITool in ${CLITools[*]}; do
|
for CLITool in ${CLITools[*]}; do
|
||||||
# Could use parameter replacement, but requires extra variable.
|
# Could use parameter replacement, but requires extra variable.
|
||||||
echo -ne "$FLUXIONVLine `printf "%-64s" "$CLITool" | sed 's/ /./g'`"
|
local line=$(printf "%-44s" "$CLITool" | sed 's/ /./g')
|
||||||
|
|
||||||
|
#line+=$([ ! hash $CLITool 2>/dev/null ] && echo "$CRed Missing!$CClr" || echo ".....$CGrn OK.$CClr")
|
||||||
if ! hash $CLITool 2>/dev/null; then
|
if ! hash $CLITool 2>/dev/null; then
|
||||||
echo -e "$CRed Missing!$CClr"
|
line+="$CRed Missing!$CClr"
|
||||||
CLIToolsMissing=1
|
CLIToolsMissing=1
|
||||||
else
|
else
|
||||||
echo -e ".....$CGrn OK.$CClr"
|
line+=".....$CGrn OK.$CClr"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
format_center "$FLUXIONVLine $line"
|
||||||
|
echo -e "$FormatCenter"
|
||||||
|
|
||||||
sleep 0.025
|
sleep 0.025
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $CLIToolsMissing ]; then
|
if [ "$CLIToolsMissing" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -269,23 +274,31 @@ if [ ! -d "$FLUXIONWorkspacePath" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! $FLUXIONDebug ]; then
|
if [ ! $FLUXIONDebug ]; then
|
||||||
clear; echo
|
clear; echo -e "$CRed"
|
||||||
sleep 0.01 && echo -e "$CRed "
|
FLUXIONBanner=()
|
||||||
sleep 0.01 && echo -e " ⌠▓▒▓▒ ⌠▓╗ ⌠█┐ ┌█ ┌▓\ /▓┐ ⌠▓╖ ⌠◙▒▓▒◙ ⌠█\ ☒┐ "
|
format_center " ⌠▓▒▓▒ ⌠▓╗ ⌠█┐ ┌█ ┌▓\ /▓┐ ⌠▓╖ ⌠◙▒▓▒◙ ⌠█\ ☒┐"; FLUXIONBanner[${#FLUXIONBanner[@]}]="$FormatCenter";
|
||||||
sleep 0.01 && echo -e " ║▒_ │▒║ │▒║ ║▒ \▒\/▒/ │☢╫ │▒┌╤┐▒ ║▓▒\ ▓║ "
|
format_center " ║▒_ │▒║ │▒║ ║▒ \▒\/▒/ │☢╫ │▒┌╤┐▒ ║▓▒\ ▓║"; FLUXIONBanner[${#FLUXIONBanner[@]}]="$FormatCenter";
|
||||||
sleep 0.01 && echo -e " ≡◙◙ ║◙║ ║◙║ ║◙ ◙◙ ║¤▒ ║▓║☯║▓ ♜◙\✪\◙♜ "
|
format_center " ≡◙◙ ║◙║ ║◙║ ║◙ ◙◙ ║¤▒ ║▓║☯║▓ ♜◙\✪\◙♜"; FLUXIONBanner[${#FLUXIONBanner[@]}]="$FormatCenter";
|
||||||
sleep 0.01 && echo -e " ║▒ │▒║__ │▒└_┘▒ /▒/\▒\ │☢╫ │▒└╧┘▒ ║█ \▒█║ "
|
format_center " ║▒ │▒║__ │▒└_┘▒ /▒/\▒\ │☢╫ │▒└╧┘▒ ║█ \▒█║"; FLUXIONBanner[${#FLUXIONBanner[@]}]="$FormatCenter";
|
||||||
sleep 0.01 && echo -e " ⌡▓ ⌡◘▒▓▒ ⌡◘▒▓▒◘ └▓/ \▓┘ ⌡▓╝ ⌡◙▒▓▒◙ ⌡▓ \▓┘ "
|
format_center " ⌡▓ ⌡◘▒▓▒ ⌡◘▒▓▒◘ └▓/ \▓┘ ⌡▓╝ ⌡◙▒▓▒◙ ⌡▓ \▓┘"; FLUXIONBanner[${#FLUXIONBanner[@]}]="$FormatCenter";
|
||||||
sleep 0.01 && echo -e " ¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯ ¯¯¯ ¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ "
|
format_center "¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯ ¯¯¯ ¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯"; FLUXIONBanner[${#FLUXIONBanner[@]}]="$FormatCenter";
|
||||||
|
|
||||||
|
for line in "${FLUXIONBanner[@]}"; do
|
||||||
|
echo "$line"; sleep 0.1
|
||||||
|
done
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
echo -e "$CRed FLUXION $CWht$FLUXIONVersion (rev. $CGrn$FLUXIONRevision$CWht)$CYel by$CWht ghost"
|
format_center "${CGrn}Site: ${CRed}https://github.com/FluxionNetwork/fluxion$CClr"; echo -e "$FormatCenter"
|
||||||
|
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
echo -e "$CGrn Site: ${CRed}https://github.com/FluxionNetwork/fluxion$CClr"
|
format_center "${CRed}FLUXION $CWht$FLUXIONVersion (rev. $CGrn$FLUXIONRevision$CWht)$CYel by$CWht ghost"; echo -e "$FormatCenter"
|
||||||
|
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
echo -n " Online Version"
|
FLUXIONVNotice="Online Version"
|
||||||
|
FLUXIONVNoticeOffset=$(($(tput cols) / 2 + ((${#FLUXIONVNotice} / 2) - 4)))
|
||||||
|
printf "%${FLUXIONVNoticeOffset}s" "Online Version"
|
||||||
|
|
||||||
check_updates &
|
check_updates &
|
||||||
spinner "$!"
|
spinner "$!"
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
FormatTabLength=8
|
||||||
|
|
||||||
|
# This should be relocated (here temporarily)
|
||||||
|
tabs -$FormatTabLength # Set tab width to var
|
||||||
|
|
||||||
|
format_strip_invisibles() {
|
||||||
|
FormatStripInvisibles=$1
|
||||||
|
|
||||||
|
# Strip color escape sequences
|
||||||
|
FormatStripInvisibles=$(echo "$FormatStripInvisibles" | sed -r 's/\\e\[([0-9]*;?[0-9]+)m//g')
|
||||||
|
|
||||||
|
# Strip control characters
|
||||||
|
FormatStripInvisibles=$(echo "$FormatStripInvisibles" | sed -r 's/\\t//g' | sed -r 's/\\n//g')
|
||||||
|
}
|
||||||
|
|
||||||
|
format_strip_specifiers() {
|
||||||
|
FormatStripSpecifiers=$(echo "$1" | sed -r 's/%[\+-]?(([0-9]+|\*)|[0-9]*\.([0-9]+|\*))?[bqdiouxXfeEgGcsnaA]//g')
|
||||||
|
}
|
||||||
|
|
||||||
|
format_list_specifiers() {
|
||||||
|
# Special specifier also included (with length value as '*').
|
||||||
|
FormatListSpecifiers=($(echo "$1" | grep -oP '%[\+-]?(([0-9]+|\*)|[0-9]*\.([0-9]+|\*))?[bqdiouxXfeEgGcsnaA]'))
|
||||||
|
}
|
||||||
|
|
||||||
|
format_emulate_expansion() {
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
format_calculate_length() {
|
||||||
|
# Retrieve string of printable characters only in format before substitution.
|
||||||
|
format_strip_invisibles "`echo "$1" | sed -r 's/%%/%1s/g'`"
|
||||||
|
local __format_calculate_length__visibles=$FormatStripInvisibles
|
||||||
|
|
||||||
|
# Calculate number of all printable characters in format before substitution.
|
||||||
|
format_strip_specifiers "$__format_calculate_length__visibles"
|
||||||
|
local __format_calculate_length__literalsLength=${#FormatStripSpecifiers}
|
||||||
|
|
||||||
|
format_list_specifiers "$__format_calculate_length__visibles"
|
||||||
|
|
||||||
|
local __format_calculate_length__staticsLength=$(echo "${FormatListSpecifiers[@]}" | grep -oP '\d+' | awk '{s+=$0} END {print s}')
|
||||||
|
|
||||||
|
FormatCalculateLength=$((__format_calculate_length__literalsLength + __format_calculate_length__staticsLength))
|
||||||
|
}
|
||||||
|
|
||||||
|
format_autosize() {
|
||||||
|
# Treat horizontal tab as a specifier with a length of tab-length.
|
||||||
|
format_calculate_length "`echo "$1" | sed -r 's/\\\\t/%'"$FormatTabLength"'s/g'`"
|
||||||
|
# Exploit the fact the previous function just calculated FormatStripSpecifiers.
|
||||||
|
local __format_autosize__dynamics_count=$(echo "${FormatListSpecifiers[@]}" | grep -oP '%[\+-]?\.?\*[bqdiouxXfeEgGcsnaA]' | wc -l)
|
||||||
|
local __format_autosize__availableLength=$(( $(tput cols) - $FormatCalculateLength ))
|
||||||
|
local __format_autosize__dynamicsLength=$(( $__format_autosize__availableLength / $__format_autosize__dynamics_count ))
|
||||||
|
FormatAutosize="$1"
|
||||||
|
FormatAutosize=$(echo "$FormatAutosize" | sed -r 's/%\*s/%'"$__format_autosize__dynamicsLength"'s/g')
|
||||||
|
FormatAutosize=$(echo "$FormatAutosize" | sed -r 's/%\.\*s/%.'"$__format_autosize__dynamicsLength"'s/g')
|
||||||
|
FormatAutosize=$(echo "$FormatAutosize" | sed -r 's/%-\*s/%-'"$__format_autosize__dynamicsLength"'s/g')
|
||||||
|
FormatAutosize=$(echo "$FormatAutosize" | sed -r 's/%-\.\*s/%-.'"$__format_autosize__dynamicsLength"'s/g')
|
||||||
|
}
|
||||||
|
|
||||||
|
format_center() {
|
||||||
|
format_strip_invisibles "$1"
|
||||||
|
local __format_center__text_length=${#FormatStripInvisibles}
|
||||||
|
format_autosize "%*s%${__format_center__text_length}s%*s"
|
||||||
|
FormatCenter=$(printf "$FormatAutosize" "" "$1" "")
|
||||||
|
#FormatCenter=$(echo "$FormatCenter" | cut -d X -f 1)"$1"$(echo "$FormatCenter" | cut -d X -f 2)
|
||||||
|
}
|
Loading…
Reference in New Issue