Rewrote FormatUtils for performance & fixed bugs.
Rewrote FormatUtils to correct bad performance (sluggish on slow systems). Changed FormatUtils API to accomodate for new performance enhancements. Added a new literal to FormatUtils's formats, the double asterisk (**). FormatUtils will now replace all asterisks, double asterisk (**). Fixed an issue caused by long ESSIDs and long interface driver descriptors.
This commit is contained in:
parent
490fea94ff
commit
0a2ce6fcd1
27
fluxion.sh
27
fluxion.sh
|
@ -224,11 +224,11 @@ trap handle_exit SIGINT SIGHUP
|
||||||
|
|
||||||
# Design
|
# Design
|
||||||
function fluxion_header() {
|
function fluxion_header() {
|
||||||
format_autosize "[%*s]\n"
|
format_apply_autosize "[%*s]\n"
|
||||||
local verticalBorder=$FormatAutosize
|
local verticalBorder=$FormatApplyAutosize
|
||||||
|
|
||||||
format_autosize "[%*s${CRed}FLUXION $FLUXIONVersion ${CRed}< F${CYel}luxion ${CRed}I${CYel}s ${CRed}T${CYel}he ${CRed}F${CYel}uture >%*s$CBlu]\n";
|
format_apply_autosize "[%*s${CRed}FLUXION $FLUXIONVersion ${CRed}< F${CYel}luxion ${CRed}I${CYel}s ${CRed}T${CYel}he ${CRed}F${CYel}uture >%*s$CBlu]\n";
|
||||||
local headerTextFormat="$FormatAutosize"
|
local headerTextFormat="$FormatApplyAutosize"
|
||||||
|
|
||||||
conditional_clear
|
conditional_clear
|
||||||
|
|
||||||
|
@ -507,8 +507,9 @@ function set_interface() {
|
||||||
if [ $WIAvailableDataCount -eq 1 -a ${WIAvailableState[0]} = '+' ]; then
|
if [ $WIAvailableDataCount -eq 1 -a ${WIAvailableState[0]} = '+' ]; then
|
||||||
WISelected="${WIAvailable[0]}"
|
WISelected="${WIAvailable[0]}"
|
||||||
else
|
else
|
||||||
|
format_apply_autosize "$CRed[$CYel%1d$CRed]%b %-8b [%1s] %*.*s\n"
|
||||||
io_query_format_fields "$FLUXIONVLine $FLUXIONInterfaceQuery" \
|
io_query_format_fields "$FLUXIONVLine $FLUXIONInterfaceQuery" \
|
||||||
"$CRed[$CYel%d$CRed]%b %-8b [%1s] %s\n" \
|
"$FormatApplyAutosize" \
|
||||||
WIAvailableColor[@] WIAvailable[@] WIAvailableState[@] WIAvailableInfo[@]
|
WIAvailableColor[@] WIAvailable[@] WIAvailableState[@] WIAvailableInfo[@]
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
@ -744,11 +745,11 @@ function set_target_ap() {
|
||||||
|
|
||||||
local headerTitle=$(format_center_static "WIFI LIST"; echo -n "$FormatCenterStatic\n\n")
|
local headerTitle=$(format_center_static "WIFI LIST"; echo -n "$FormatCenterStatic\n\n")
|
||||||
|
|
||||||
format_autosize "$CRed[$CYel * $CRed]$CClr %-*s %4s %3s %3s %2s %8s %18s\n"
|
format_apply_autosize "$CRed[$CYel ** $CRed]$CClr %-*.*s %4s %3s %3s %2s %8.8s %18s\n"
|
||||||
local headerFields=$(printf "$FormatAutosize" "ESSID" "QLTY" "PWR" "STA" "CH" "SECURITY" "BSSID")
|
local headerFields=$(printf "$FormatApplyAutosize" "ESSID" "QLTY" "PWR" "STA" "CH" "SECURITY" "BSSID")
|
||||||
|
|
||||||
format_autosize "$CRed[$CYel%03d$CRed]%b %-*s %3s%% %3s %3d %2s %8s %18s\n"
|
format_apply_autosize "$CRed[$CYel%03d$CRed]%b %-*.*s %3s%% %3s %3d %2s %8.8s %18s\n"
|
||||||
io_query_format_fields "$headerTitle$headerFields" "$FormatAutosize" \
|
io_query_format_fields "$headerTitle$headerFields" "$FormatApplyAutosize" \
|
||||||
TargetAPCandidatesColor[@] \
|
TargetAPCandidatesColor[@] \
|
||||||
TargetAPCandidatesESSID[@] \
|
TargetAPCandidatesESSID[@] \
|
||||||
TargetAPCandidatesQuality[@] \
|
TargetAPCandidatesQuality[@] \
|
||||||
|
@ -778,11 +779,11 @@ function set_target_ap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function view_target_ap_info() {
|
function view_target_ap_info() {
|
||||||
format_autosize "%*s$CBlu%7s$CClr: %-32b%*s\n"
|
format_apply_autosize "%*s$CBlu%7s$CClr: %-32b%*s\n"
|
||||||
|
|
||||||
printf "$FormatAutosize" "" "ESSID" "$APTargetSSID / $APTargetEncryption" ""
|
printf "$FormatApplyAutosize" "" "ESSID" "$APTargetSSID / $APTargetEncryption" ""
|
||||||
printf "$FormatAutosize" "" "Channel" "$APTargetChannel" ""
|
printf "$FormatApplyAutosize" "" "Channel" "$APTargetChannel" ""
|
||||||
printf "$FormatAutosize" "" "BSSID" "$APTargetMAC ($CYel${APTargetMaker:-UNKNOWN}$CClr)" ""
|
printf "$FormatApplyAutosize" "" "BSSID" "$APTargetMAC ($CYel${APTargetMaker:-UNKNOWN}$CClr)" ""
|
||||||
|
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,74 +1,136 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
FormatTabLength=8
|
FormatTabLength=8
|
||||||
|
FormatValidSpecifiers='%([+-]?([0-9]+|\*)?(\.([0-9]+|\*))?)?[bqdiouxXfeEgGcsnaA]'
|
||||||
|
|
||||||
# This should be relocated (here temporarily)
|
# This should be relocated (here temporarily)
|
||||||
tabs -$FormatTabLength # Set tab width to var
|
tabs -$FormatTabLength # Set tab width to var
|
||||||
|
|
||||||
format_strip_invisibles() {
|
#format_strip_specifiers() {
|
||||||
FormatStripInvisibles=$1
|
# FormatStripSpecifiers=$(echo "$1" | sed -r "s/$FormatValidSpecifiers//g")
|
||||||
|
#}=
|
||||||
|
|
||||||
# Strip color escape sequences
|
function format_strip_invisibles() {
|
||||||
FormatStripInvisibles=$(echo "$FormatStripInvisibles" | sed -r 's/\\e\[([0-9]*;?[0-9]+)m//g')
|
# This function currently only strips the following:
|
||||||
|
# Color escape sequences, & control characters
|
||||||
# Strip control characters
|
FormatStripInvisibles=$(echo "$1" | sed -r 's/\\(e\[([0-9]*;?[0-9]+)m|(t|n))//g')
|
||||||
FormatStripInvisibles=$(echo "$FormatStripInvisibles" | sed -r 's/\\t//g' | sed -r 's/\\n//g')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
format_strip_specifiers() {
|
function format_expand_invisibles() {
|
||||||
FormatStripSpecifiers=$(echo "$1" | sed -r 's/%[\+-]?(([0-9]+|\*)|[0-9]*\.([0-9]+|\*))?[bqdiouxXfeEgGcsnaA]//g')
|
FormatExpandInvisibles=$(echo "$1" | sed -r 's/\\(e\[([0-9]*;?[0-9]+)m|n)/%0s/g; s/\\t/%'"$FormatTabLength"'s/g')
|
||||||
}
|
}
|
||||||
|
|
||||||
format_list_specifiers() {
|
function format_list_specifiers() {
|
||||||
# Special specifier also included (with length value as '*').
|
# Special specifier also included (with length value as '*').
|
||||||
FormatListSpecifiers=($(echo "$1" | grep -oP '%[\+-]?(([0-9]+|\*)|[0-9]*\.([0-9]+|\*))?[bqdiouxXfeEgGcsnaA]'))
|
FormatListSpecifiers=($(echo "$1" | grep -oP "$FormatValidSpecifiers"))
|
||||||
}
|
}
|
||||||
|
|
||||||
format_emulate_expansion() {
|
# Statics are all specifiers with a fixed size
|
||||||
echo
|
function format_calculate_statics_length() {
|
||||||
|
local __format_calculate_statics_length__specifiers=("${!2}")
|
||||||
|
|
||||||
|
if [ ! "$2" ]; then
|
||||||
|
echo "format_calculate_statics_length missing \$2"
|
||||||
|
format_list_specifiers "$1"
|
||||||
|
__format_calculate_statics_length__specifiers=("${FormatListSpecifiers[@]}")
|
||||||
|
fi
|
||||||
|
FormatCalculateStaticsLength=$(echo "${__format_calculate_statics_length__specifiers[@]}" | sed -r 's/\.[0-9]+s/s/g' | grep -oP '\d+' | awk 'BEGIN {s=0} {s+=$0} END {print s}')
|
||||||
}
|
}
|
||||||
|
|
||||||
format_calculate_length() {
|
function format_calculate_literals_length() {
|
||||||
# Retrieve string of printable characters only in format before substitution.
|
local __format_calculate_literals_length__normalizedFormat="`echo "$2" | sed -r 's/%%|\*\*/%1s/g'`"
|
||||||
format_strip_invisibles "`echo "$1" | sed -r 's/%%/%1s/g'`"
|
local __format_calculate_literals_length__specifiers=("${!3}")
|
||||||
local __format_calculate_length__visibles=$FormatStripInvisibles
|
|
||||||
|
|
||||||
# Calculate number of all printable characters in format before substitution.
|
if [ ! "$2" ]; then
|
||||||
format_strip_specifiers "$__format_calculate_length__visibles"
|
echo "format_calculate_literals_length missing \$2"
|
||||||
local __format_calculate_length__literalsLength=${#FormatStripSpecifiers}
|
format_strip_invisibles "$1"
|
||||||
|
__format_calculate_literals_length__normalizedFormat="`echo "$FormatStripInvisibles" | sed -r 's/%%|\*\*/%1s/g'`"
|
||||||
|
fi
|
||||||
|
|
||||||
format_list_specifiers "$__format_calculate_length__visibles"
|
if [ ! "$3" ]; then
|
||||||
|
echo "format_calculate_literals_length missing \$3"
|
||||||
|
format_list_specifiers "$1"
|
||||||
|
__format_calculate_literals_length__specifiers=("${FormatListSpecifiers[@]}")
|
||||||
|
fi
|
||||||
|
|
||||||
local __format_calculate_length__staticsLength=$(echo "${FormatListSpecifiers[@]}" | grep -oP '\d+' | awk '{s+=$0} END {print s}')
|
FormatCalculateLiteralsLength=$((${#__format_calculate_literals_length__normalizedFormat} - ($(echo "${__format_calculate_literals_length__specifiers[@]}" | wc -m) - ${#__format_calculate_literals_length__specifiers[@]})))
|
||||||
|
|
||||||
FormatCalculateLength=$((__format_calculate_length__literalsLength + __format_calculate_length__staticsLength))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: This function's performance could sure use improvement...
|
function format_calculate_dynamics_length() {
|
||||||
# This is a semi-permanent fix, unless someone wants to tackle it...
|
local __format_calculate_dynamics_length__staticsLength=$2
|
||||||
format_autosize() { # Note that this does not yet support multiple lines (multiple \n).
|
local __format_calculate_dynamics_length__literalsLength=$3
|
||||||
# Treat horizontal tab as a specifier with a length of tab-length.
|
|
||||||
format_calculate_length "`echo "$1" | sed -r 's/\\\\t/%'"$FormatTabLength"'s/g'`"
|
if [ ! "$2" ]; then
|
||||||
# Exploit the fact the previous function just calculated FormatStripSpecifiers.
|
echo "format_calculate_dynamics_length missing \$2"
|
||||||
local __format_autosize__dynamics_count=$(echo "${FormatListSpecifiers[@]}" | grep -oP '%[\+-]?\.?\*[bqdiouxXfeEgGcsnaA]' | wc -l)
|
format_expand_invisibles "$1"
|
||||||
local __format_autosize__availableLength=$(( $(tput cols) - $FormatCalculateLength ))
|
format_list_specifiers "$FormatExpandInvisibles"
|
||||||
local __format_autosize__dynamicsLength=$(( $__format_autosize__availableLength / $__format_autosize__dynamics_count ))
|
format_calculate_statics_length X FormatListSpecifiers[@]
|
||||||
FormatAutosize=$(echo "$1" | sed -r 's/%\*s/%'"$__format_autosize__dynamicsLength"'s/g' | \
|
__format_calculate_dynamics_length__staticsLength=$FormatCalculateStaticsLength
|
||||||
sed -r 's/%\.\*s/%.'"$__format_autosize__dynamicsLength"'s/g' | \
|
fi
|
||||||
sed -r 's/%-\*s/%-'"$__format_autosize__dynamicsLength"'s/g' | \
|
|
||||||
sed -r 's/%-\.\*s/%-.'"$__format_autosize__dynamicsLength"'s/g')
|
if [ ! "$3" ]; then
|
||||||
|
if [ "$2" ]; then
|
||||||
|
format_expand_invisibles "$1"
|
||||||
|
format_list_specifiers "$FormatExpandInvisibles"
|
||||||
|
fi
|
||||||
|
echo "format_calculate_dynamics_length missing \$3"
|
||||||
|
format_calculate_literals_length X "$FormatExpandInvisibles" FormatListSpecifiers[@]
|
||||||
|
__format_calculate_dynamics_length__literalsLength=$FormatCalculateLiteralsLength
|
||||||
|
fi
|
||||||
|
|
||||||
|
FormatCalculateDynamicsLength=$(( $(tput cols) - (__format_calculate_dynamics_length__staticsLength + __format_calculate_dynamics_length__literalsLength) ))
|
||||||
}
|
}
|
||||||
|
|
||||||
format_center_static() {
|
function format_calculate_autosize_length() {
|
||||||
|
local __format_calculate_autosize_length__dynamicsLength=$2
|
||||||
|
local __format_calculate_autosize_length__dynamicsCount=$3
|
||||||
|
|
||||||
|
if [ ! "$2" ]; then
|
||||||
|
format_expand_invisibles "$1"
|
||||||
|
format_list_specifiers "$FormatExpandInvisibles"
|
||||||
|
format_calculate_statics_length X FormatListSpecifiers[@]
|
||||||
|
format_calculate_literals_length X "$FormatExpandInvisibles" FormatListSpecifiers[@]
|
||||||
|
format_calculate_dynamics_length X "$FormatCalculateStaticsLength" "$FormatCalculateLiteralsLength"
|
||||||
|
__format_calculate_autosize_length__dynamicsLength=$FormatCalculateDynamicsLength
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! "$3" ]; then
|
||||||
|
if [ "$2" ]
|
||||||
|
then format_list_specifiers "$1"
|
||||||
|
fi
|
||||||
|
# local __format_calculate_autosize_length__dynamics=("${FormatListSpecifiers[@]}")
|
||||||
|
# ("`echo "${FormatListSpecifiers[@]}" | awk '{ for(i = 1; i <= NF; i++) { if ($i !~ /[0-9]+/) print $i; } }'`")
|
||||||
|
__format_calculate_autosize_length__dynamicsCount=0
|
||||||
|
for __format_calculate_autosize_length__specifier in "${FormatListSpecifiers[@]}"; do
|
||||||
|
if echo "$__format_calculate_autosize_length__specifier" | grep '\*' >/dev/null 2>&1; then
|
||||||
|
((__format_calculate_autosize_length__dynamicsCount++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $__format_calculate_autosize_length__dynamicsCount -ne 0 -a \
|
||||||
|
$__format_calculate_autosize_length__dynamicsLength -ge 0 ]
|
||||||
|
then FormatCalculateAutosizeLength=$(( __format_calculate_autosize_length__dynamicsLength / __format_calculate_autosize_length__dynamicsCount ))
|
||||||
|
else FormatCalculateAutosizeLength=0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Note that this does not yet support multiple lines (multiple \n).
|
||||||
|
function format_apply_autosize() {
|
||||||
|
format_calculate_autosize_length "$1"
|
||||||
|
FormatApplyAutosize=$(echo "$1" | sed -r 's/\*\.\*/'"$FormatCalculateAutosizeLength"'.'"$FormatCalculateAutosizeLength"'/g; s/(^|[^*])\*([^*]|$)/\1'"$FormatCalculateAutosizeLength"'\2/g; s/\*\*/*/g')
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_center_static() {
|
||||||
format_strip_invisibles "$1"
|
format_strip_invisibles "$1"
|
||||||
local __format_center_static__text_length=${#FormatStripInvisibles}
|
local __format_center_static__text_length=${#FormatStripInvisibles}
|
||||||
format_autosize "%*s%${__format_center_static__text_length}s%*s"
|
format_apply_autosize "%*s%${__format_center_static__text_length}s%*s"
|
||||||
FormatCenterStatic=$(printf "$FormatAutosize" "" "$1" "")
|
FormatCenterStatic=$(printf "$FormatApplyAutosize" "" "$1" "")
|
||||||
}
|
}
|
||||||
|
|
||||||
format_center_dynamic() {
|
function format_center_dynamic() {
|
||||||
format_calculate_length "$1"
|
format_calculate_length "$1"
|
||||||
format_autosize "%*s%${FormatCalculateLength}s%*s"
|
format_apply_autosize "%*s%${FormatCalculateLength}s%*s"
|
||||||
# Temporary, I'll find a better solution later (too tired).
|
# Temporary, I'll find a better solution later (too tired).
|
||||||
FormatCenterDynamic=$(printf "`echo "$FormatAutosize" | sed -r 's/%[0-9]+s/%s/2'`" "" "$1" "")
|
FormatCenterDynamic=$(printf "`echo "$FormatApplyAutosize" | sed -r 's/%[0-9]+s/%s/2'`" "" "$1" "")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue