This commit is contained in:
pyr0ball 2023-05-07 22:01:38 -07:00
commit a2aabfb78f
2 changed files with 12 additions and 12 deletions

View file

@ -15,6 +15,4 @@ With all of these tools combined, you can make powerful interactive scripts with
run `./demo.sh` for example output
![image](https://user-images.githubusercontent.com/8482805/224919713-d1ec4723-1909-470d-93d6-1b7091de8de8.png)
![image](https://user-images.githubusercontent.com/8482805/224919800-2d4450e4-9fc7-4ef7-b432-9ccfd0278880.png)
![image](https://user-images.githubusercontent.com/8482805/224919970-0444b849-5959-49b5-a187-b6a214ccc84f.png)
![image](https://user-images.githubusercontent.com/8482805/235781738-f31481a8-946d-4051-9210-3df28687a19c.png)

View file

@ -2,7 +2,7 @@
# pyr0ball script functions library
# Initial Vars
functionsrev=1.1.10
functionsrev=1.1.11
#scriptname="${BASH_SOURCE[0]##*/}"
#rundir="${BASH_SOURCE[0]%/*}"
#rundir_absolute=$(cd $rundir && pwd)
@ -337,19 +337,18 @@ boxseparator(){
# For printing center-justified text. To change the padding character, replace the ' ' <~~ whitespace in front of the '{' in the padding variable
center() {
local _cmd=$@
local padding="";
padding="$(printf '%0.1s' \ {1..100})"
#padding=" "
printf '%*.*s %s %*.*s\n' 0 "$(((BOXWIDTH-2-${#_cmd[@]})/2))" "${padding}" "$_cmd" 0 "$(((BOXWIDTH-1-${#_cmd})/2))" "${padding}"
printf '%*.*s %s %*.*s\n' 0 "$(((BOXWIDTH-2-${#1})/2))" "${padding}" "$1" 0 "$(((BOXWIDTH-1-${#1})/2))" "${padding}"
}
# For printing spanned text, e.g. single-pair lists ($name...$title)
spanner() {
# 1: left-side-text, 2: right-side-text
local spanner="";
eval printf -v spanner \'"%0.1s"\' "-"{1..$[$((BOXWIDTH-4))- 2 - ${#1} - ${#2}]}
printf "%s %s %s\n" "$1" "$spanner" "$2";
local _spanner="";
eval printf -v _spanner \'"%0.1s"\' "-"{1..$[$((BOXWIDTH-4))- 2 - ${#1} - ${#2}]}
printf "%s %s %s\n" "$1" "$_spanner" "$2";
}
boxborder(){
@ -413,11 +412,14 @@ popdfail(){
}
logger(){
#$@ 2>&1 | tee >(ts "[$scriptname][%d-%m-%y %H_%M_%S]" > $logfile) # This version of prepend requires the 'ts' utility from 'moreutils' package
$@ 2>&1 | tee >(
while IFS= read -r line; do
_line=$(echo $line | sed "s,\x1B\[[0-9;]*[mK],,g" | tr -dc '[:print:]')
printf '[%s] %s\n' "${scriptname}][${prettyDate}" "$_line"
# strip any escaped strings for logging output
_line=$(echo $line | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | tr -dc '[:print:]')
# only print out non-empty lines to log
if [[ "$_line" != "" ]] ; then
printf '[%s] %s\n' "${scriptname}][${pretty_date}" "$_line"
fi
done >> $logfile
)
}