Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
Last active October 5, 2017 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThinGuy/78cec19c778a9bcd1f00b2dc2f66c60e to your computer and use it in GitHub Desktop.
Save ThinGuy/78cec19c778a9bcd1f00b2dc2f66c60e to your computer and use it in GitHub Desktop.
Text related parameters and functions for bash scripts
## Don't change the location of the RSCHK line. It must be first.
RSCHK=$_
TRUE=true
FALSE=false
TEXT_FU_FUNCTIONS_VER=1.0
SOURCEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
#Ensure that this script is being sourced, rather than being executed
[[ $RSCHK != $0 ]] || { echo "Error: ${SOURCEDIR}/${BASH_SOURCE[0]##*/} is being ran directly! Please \"source\" this script."; sleep 500;return; }
## Text related attributes and functions ##
#Function to get current columns (width) of terminal
COLS=$(stty size|sed "s/^.* //g")
#Function to get current rows (height) of terminal
ROWS=$(stty size|sed "s/ .*$//g")
#Underline Text
export UT='\e[4m'
#Italic Text
export IT='\e[3m'
#Bold Underline Text
export BUT='\e[1;4m'
#Bold Italic Text
export BIT='\e[1;3m'
#BS = Backspace
export BS='\b'
#Bold Text
export BT='\e[0;1m'
#Bold current Text (no reset
export RCT='\e[1m'
#Regular or Reset Text
export RT='\e[0m'
#Bold Red
export BR='\e[0;1;38;2;255;0;0m'
#Bold Green
export BG='\e[0;1;38;2;0;255;0m'
#Bold Yellow
export BY='\e[0;1;38;2;225;225;0m'
#Bold Blue
export BB='\e[0;1;38;2;0;0;255m'
#Bold Magenta
export BM='\e[0;1;38;2;255;0;255m'
#Bold Pink
export BP='\e[0;1;38;2;255;150;150m'
#Bold Cyan
export BC='\e[0;1;38;2;100;255;255m'
#Bold White
export BW='\e[0;1;38;2;255;255;255m'
#Bold Orange
export BO='\e[0;1;38;2;225;95;0m'
#Bold Light Grey
export BL='\e[0;1;38;2;225;225;225m'
#Bold Dark Grey
export BD='\e[0;1;38;2;100;100;100m'
#Regular Red
export RR='\e[0;0;38;2;255;0;0m'
#Regular Green
export RG='\e[0m\e[0;0;38;2;0;255;0m'
#Regular Yellow
export RY='\e[0;0;38;2;225;225;0m'
#Regular Blue
export RB='\e[0;0;38;2;0;0;255m'
#Regular Magenta
export RM='\e[0;0;38;2;255;0;255m'
#Regular Pink
export RP='\e[0;0;38;2;255;150;150m'
#Regular Cyan
export RC='\e[0;0;38;2;100;255;255m'
#Regular White
export RW='\e[0;0;38;2;255;255;255m'
#Regular Orange
export RO='\e[0;0;38;2;225;95;0m'
#Regular Light Grey
export RL='\e[0;0;38;2;225;225;225m'
#Regular Dark Grey
export RD='\e[0;0;38;2;100;100;100m'
#Reverse White Orange
export RWO='\e[0;1;38;2;225;95;0m\e[48;2;255;255;255m'
#Revese Orage White
export ROW='\e[0;1;38;2;255;255;255m\e[48;2;225;95;0m'
export RAUBW='\e[0;1;48;5;89m'
export RWAUB='\e[0;1;38;5;89;48;5;255m'
export RAUBW='\e[0;1;48;5;89;38;5;255m'
export RYW='\e[0;1;5;43;37m'
export RRW='\e[0;38;2;255;255;255m\e[48;2;255;0;0m'
export RGW='\e[0;1;5;42;37m'
export RBW='\e[0;1;5;44;37m'
export RGRW='\e[0;1;5;47;37m'
export RMW='\e[0;1;5;45;37m'
export RCW='\e[0;1;5;46;37m'
export RYB='\e[0m\e[5;43;30m'
export RRB='\e[0m\e[5;41;30m'
export RGB='\e[0m\e[5;42;30m'
export RWB='\e[0m\e[5;47;30m'
export RGrB='\e[0m\e[5;47;30m'
export RMB='\e[0m\e[5;45;30m'
export RCB='\e[0m\e[5;47;30m'
export RGBBW='\e[0;1;38;2;255;255;255m'
export RGBBB='\e[0;1;38;2;1;1;0m'
export RGBRWB='\e[0;1;38;2;1;1;0m\e[48;2;255;255;255m'
#LXD Foreground Colors Light Grey, Dark Grey, Reg Grey, Orange
LXDLG='\e[0m\e[1;38;2;205;205;205m'
LXDDG='\e[0m\e[1;38;2;51;51;51m'
LXDRG='\e[0m\e[1;38;2;136;136;136m'
LXDOR='\e[0m\e[1;38;2;221;72;20m'
#LXD Background Colors Light Grey, Dark Grey, Reg Grey, Orange
LXDRLG='\e[0;48;2;205;205;205m'
LXDRDG='\e[1;48;2;51;51;51m'
LXDRRG='\e[1;48;2;136;136;136m'
LXDROR='\e[1;48;2;221;72;20m'
#Variables for ubuntu logo utf-8 character
if [[ $(dpkg 2>/dev/null -l ttf-ubuntu-font-family|/bin/grep -oE '^ii') ]];then
export ULOGO="${RT}\UFEFF\UE0FF\UFEFF${RT}"
export ULOGOC="${RO}\UFEFF\UE0FF\UFEFF${RT}"
export ULOGOBG="${RO}${RWO}\UFEFF\UE0FF\UFEFF${RT}"
export ULOGORBG="${RT}${ROW}\UFEFF\UE0FF\UFEFF${RT}"
else
export ULOGO=
export ULOGOC=
export ULOGOBG=
export ULOGORBG=
fi
#install all available language packs
install-all-lang-packs() {
sudo apt install -y $(apt-cache search "^language-pack-[a-z][a-z]$" |awk '{print $1}')
}
#fix and locale related issues
fix-locale() {
local AVAILANGS=($(awk '{print $1}' /usr/share/i18n/SUPPORTED))
[[ -z ${1} ]] && { printf "\e[2GPlease provide locale name (i.e. \"en_US.UTF-8)\"\n";return 1; }
[[ $(printf "%s\n" ${AVAILANGS[@]}|/bin/grep -oE ''${1}'') ]] || { printf "\e[2G${1} is not a valid locale name\n";return 1; }
for VAR in $(locale|/bin/grep -oE '^L[^=]+');do
if [[ ${VAR} = "LC_ALL" ]];then local MYLANG= || local MYLANG=${1}
elif [[ ${VAR} = "LANGUAGE" ]];then local MYLANG=${1%%.*}
else
local MYLANG=${1}
fi
sed -i '/export '${VAR}'/d' ~/.bashrc
sudo sed -i '/export '${VAR}'/d' /etc/default/locale
sudo sed -i '/export '${VAR}'/d' /etc/environment
echo "export ${VAR}=${MYLANG}"|tee 1>/dev/null -a ~/.bashrc
echo "export ${VAR}=${MYLANG}"|sudo tee 1>/dev/null -a /etc/default/locale
echo "export ${VAR}=${MYLANG}"|sudo tee 1>/dev/null -a /etc/environment
done
printf 'locales locales/default_environment_locale select '${1}'\n'|sudo debconf-set-selections
printf 'locales locales/locales_to_be_generated multiselect '${1}'\n'|sudo debconf-set-selections
#printf 'locales locales/locales_to_be_generated multiselect All locales\n'|sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive locales
sudo locale-gen ${1}
sudo localedef -i ${1%%.*} -c -f ${1##*.} ${1}
}
getlinesize() {
local DESC="${RO}${FUNCNAME}${RT}: Returns width and height of a string. Returns longest width for multiline strings"
getcurpos_usage() {
printf "\n\e[2G${DESC}\n"
printf "\n\e[2GUsage: ${FUNCNAME%%_*} [OPTIONS]\n"
printf "\n\e[2GOptions:\n\n"
printf "\e[2G-w, --width \e[25GOnly width\n"
printf "\e[2G-h, --height \e[25GOnly height\n"
printf "\n"
}
local PRINTWID=${FALSE}
local PRINTHGT=${FALSE}
ARGS=`getopt -o whd -l width,height,help,desc -n ${FUNCNAME} -- "$@"`
eval set -- "$ARGS"
while true ; do
case "$1" in
-w|--width) local PRINTLINE=${TRUE};shift 1;;
-h|--height) local PRINTCOL=${TRUE};shift 1;;
--help) ${FUNCNAME}_usage;return 2;;
-d|--desc) printf "${DESC}\n";return;;
--) shift;break;;
esac
done
unset LSTR LINES LINEH LINEW
LINEH=0 LINEW=0
local LSTR=$@
while IFS= read -r L;do LINES+=($(echo "$L"|wc -m));done < <(printf "${LSTR}"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g')
local LINEH=${#LINES[@]}
for i in ${!LINES[@]};do local LINEW=$((${LINES[$i]}>${LINEW}?${LINES[$i]}:${LINEW}));done
unset LINES
if [[ ${PRINTWID} = ${TRUE} && ${PRINTHGT} = ${TRUE} ]];then { echo "$LINEW;$LINEH";return 0; }
elif [[ ${PRINTWID} = ${FALSE} && ${PRINTHGT} = ${FALSE} ]];then { echo "$LINEW;$LINEH";return 0; }
elif [[ ${PRINTWID} = ${TRUE} ]];then echo $LINEW
elif [[ ${PRINTHGT} = ${TRUE} ]];then echo $LINEH
fi
}
getcurpos() {
local DESC="${RO}${FUNCNAME}${RT}: Returns current line and/or column of the terminal cursor"
getcurpos_usage() {
printf "\n\e[2G${DESC}\n"
printf "\n\e[2GUsage: ${FUNCNAME%%_*} [OPTIONS]\n"
printf "\n\e[2GOptions:\n\n"
printf "\e[2G-l, --line \e[25GOnly print line position\n"
printf "\e[2G-c, --col \e[25GOnly print column position\n"
printf "\n"
}
local PRINTLINE=${FALSE}
local PRINTCOL=${FALSE}
ARGS=`getopt -o lchd -l line,col,help,desc -n ${FUNCNAME} -- "$@"`
eval set -- "$ARGS"
while true ; do
case "$1" in
-l|--line) local PRINTLINE=${TRUE};shift 1;;
-c|--col) local PRINTCOL=${TRUE};shift 1;;
-h|--help) ${FUNCNAME}_usage;return 2;;
-d|--desc) printf "${DESC}\n";return;;
--) shift;break;;
esac
done
local oldstty=$(stty -g)
stty raw -echo min 0
printf '\e[6n' > $(tty)
IFS=';' read -r -d R -a CURPOS
stty $oldstty
local CUR_LINE=$((${CURPOS[0]:2} - 1))
local CUR_COL=$((${CURPOS[1]} - 1))
if [[ ${PRINTLINE} = ${TRUE} && ${PRINTCOL} = ${TRUE} ]];then { echo "$CUR_LINE;$CUR_COL";return 0; }
elif [[ ${PRINTLINE} = ${FALSE} && ${PRINTCOL} = ${FALSE} ]];then { echo "$CUR_LINE;$CUR_COL";return 0; }
elif [[ ${PRINTLINE} = ${TRUE} ]];then echo $CUR_LINE
elif [[ ${PRINTCOL} = ${TRUE} ]];then echo $CUR_COL
fi
}
install-figlet() {
sudo apt install figlet toilet libcaca0 caca-utils -y
}
get-fig-fonts() {
local FIGFONTDIR=$(find 2>/dev/null /usr -type f -iname "*.flf" -exec dirname "{}" \; |sort -u)
[[ -n ${FIGFONTDIR} && -d ${FIGFONTDIR} ]] || install-figlet
[[ -n ${FIGFONTDIR} && -d ${FIGFONTDIR} ]] && curl -sSL ftp://ftp.figlet.org/pub/figlet/fonts/contributed.tar.gz|sudo tar xzvf - --strip 1 -C ${FIGFONTDIR}
}
fig-scroll() {
local DESC="${RO}${FUNCNAME}${RT}: Scroll figlet text"
fig-scroll_usage() {
printf "\n\e[2G${DESC}\n"
printf "\n\e[2GUsage: ${FUNCNAME%%_*} [OPTIONS]\n"
printf "\n\e[2GOptions:\n\n"
printf "\e[2G-f, --font \e[25GName of figlet font (see \"showfigfonts\")\n"
printf "\e[2G-t, --text \e[25GText to scroll\n"
printf "\e[2G-j, --justify \e[25G(left|center [default]|right)\n"
printf "\n"
}
local TRUE=true
local FALSE=false
ARGS=$(getopt -o f:t:j:hd -l font:,text:,justify:,help,desc -n ${FUNCNAME} -- "$@" 2>/dev/null)
[[ $? -eq 1 ]] && { ${FUNCNAME}_usage;return 2; }
eval set -- "$ARGS"
while true ; do
case "$1" in
-f|--font) local FFONT="${2}";shift 2;;
-t|--text) local TEXT="${2}";shift 2;;
-j|--justify) local JTEXT="${2}";shift 2;;
-h|--help) ${FUNCNAME}_usage;return 2;;
-d|--desc) printf "${DESC}\n";return;;
--) shift;break;;
*) printf "\e[2G Invalid option: ${1}\n";${FUNCNAME}_usage;return 2;;
esac
done
[[ ${JTEXT} =~ [C|c] ]] && local JCMD='-c'
[[ ${JTEXT} =~ [L|l] ]] && local JCMD='-l'
[[ ${JTEXT} =~ [R|r] ]] && local JCMD='-r'
[[ -z ${JTEXT} ]] && local JCMD='-c'
[[ -z ${FFONT} ]] && local FFONT=standard
[[ -f ${FFONT} || -n $(find /usr/share/figlet/ -type f -name "${FFONT}.[t|l]lf") || -n $(find /usr/share/figlet/ -type f -name "${FFONT}*") ]] || { printf "\e[2GError: Cannot find figlet font named ${FFONT} or ${FFONT}.[t|f]lf\n";return; }
local MCMD='figlet -f ${FFONT} -w $(tput cols) ${JCMD} -W "${TEXT}"'
local MSG=$(eval $MCMD|sed '/^ * $/d';echo)
local MSG=$(printf "\n$MSG\n")
local THGHT=$(printf "$MSG\n"|wc -l)
EOC=$(($(tput cols)-10))
scf && printf "\e[2J" && clear
while [[ $(getcurpos -l) -lt $(tput lines) ]];do
#printf "\e[${EOC}G 1st - $(getcurpos -l)"
printf "$MSG\n"|\
while IFS= read -re LINE;do
printf "$LINE\n"
done
#printf "\e[${EOC}G 2nd - $(getcurpos -l)"
[[ $(($(getcurpos -l) + 1)) -ge $(tput lines) ]] && break
#sleep .05
printf "\e[K"
#printf "\e[${EOC}G 3rd - $(getcurpos -l)"
#for i in $(seq 1 1 ${THGHT});do
# printf "\e[K\e[1B"
#done
printf "\e[${THGHT}A\e[K\e[1B"
#printf "\e[${EOC}G 3rd - $(getcurpos -l)"
#break
done
sco
}
vert-text() {
vert-text_Usage() { printf '\n\e[1m'${FUNCNAME%_*}':\e[0m Prints Vertical Text\n\n\e[1mUsage:\e[0m '${FUNCNAME%_*}' -x <horizontal offset> -y <vertical offset> <string>\n\n' 1>&2; return; }
local OPTIND o a
while getopts ":x:y::h" o; do
case "${o}" in
x) xoff="${OPTARG}"
;;
y) yoff="${OPTARG}"
;;
h) ${FUNCNAME}_Usage
return 0
;;
esac
done
shift "$((OPTIND-1))"
#Everthing after the args is the text to veritcally print
TEXT=$(printf "${@}")
[[ -z ${xoff} ]] && xoff=$(getcurpos -c) || xoff=$(($(getcurpos -c)+$xoff))
[[ -z ${yoff} ]] && yoff=$(getcurpos -l) || yoff=$(($(getcurpos -l)+$yoff))
LineLen=$(echo -n ${TEXT}|sed -e 's/\\e[[0-9;]*[a-zA-Z]//g' -e 's/\\n//g' -e's/\\e[[0-9]m//g'|wc -m)
VADJUST=1
printf "\e[${yoff};${xoff}f"
printf '\e[s'
for CHAR in $(echo ${TEXT}|grep -o .);do
printf '\e[u'
printf '\e['${VADJUST}'B\u2005'"${CHAR}"''
VADJUST=$((${VADJUST}+1))
done
#printf '\n'
unset TEXT CHAR VADJUST xoff yoff CUR_LINE CUR_COL
}
#turn on cursor
sco () {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Turn cursor on\n";return; }
setterm --cursor on;
}
#turn off cursor
scf () {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Turn cursor off\n";return; }
setterm --cursor off;
}
#turn on linewrap
lwo () {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Turn linewrap on\n";return; }
setterm --linewrap on;
}
#turn off linewrap
lwf () {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Turn linewrap off\n";return; }
setterm --linewrap off;
}
#function to echo,vi, then source a file
evs () {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Clears (via echo), edits (vi), then sources a given file\n";return; }
[[ ! -x ${1} && -f ${1} ]] && { echo > ${1};vi ${1};source ${1}; } || { printf "${RR}ERROR${RT}: ${1} is either executable or does not exist\n";return; }
}
#Display a text based status message based on $?
tstatus() {
RETCODE=$(echo $?)
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Displays text-based status message.\n";return; }
tstatus_Usage() { printf "\n${RT}Function: ${RO}${FUNCNAME%_*}${RT}\n\n${RO}Purpose:${RT} Displays an OK or FAIL message based on value of \$?\n\nUsage: <command>;${FUNCNAME%_*}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
if [[ $RETCODE -eq 0 ]];then
{ printf '\e['$(($COLS-5))'G'${RT}'[ '${RG}'OK'${RT}' ]'${RT}'\n';return $RETCODE; }
elif [[ $RETCODE -eq 1 ]];then
{ printf '\e['$(($COLS-5))'G'${RT}'['${RR}'FAIL'${RT}']'${RT}'\n';return $RETCODE; }
elif [[ $RETCODE -eq 9 ]];then
# Added for work with juju charms. Displays "AUTH" if authentication is required
{ printf '\e[73G'${RT}'['${RT}'AUTH'${RT}']'${RT}'\n';return $RETCODE; }
fi
}
#Display an icon-based status message based on $?
sstatus() {
RETCODE=$(echo $?)
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Displays an icon-based status message.\n";return; }
if [[ $RETCODE -eq 0 ]];then
{ printf '\e['$(($COLS-5))'G'${RG}' \u2714\u2003'${RT}'\n';return $RETCODE; }
elif [[ $RETCODE -eq 9 ]];then
# Added for work with juju charms. Displays a key so show that auth is required
{ printf '\e[73G'${RY}' \U1F511 '${RT}'\n';return $RETCODE; }
elif [[ $RETCODE -eq 1 ]];then
{ printf '\e['$(($COLS-5))'G'${RR}'\u2006\u2716\u2003'${RT}'\n';return $RETCODE; }
fi
}
#A spinner made from 100% whimsical fuckery
Sparkles() {
[[ $1 = '--desc' ]] && { printf "${BO}${FUNCNAME}${RT}: A wait wheel of sorts.\n";return; }
declare -a MSG=("¸" "." "•" "\*" "\¨" "\*" "•" "." "¸")
local TheMsg="${1}"
local StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
printf "\r${TheMsg} "
for a in {0..2};do
for b in {0..3};do
for i in {0..8};do
printf "\e[38;5;$((234+${a}+${b}+${i}))m"
printf "${MSG[${i}]/\\/}\e[0m";sleep .01
done
done
sleep .15;printf "\r${TheMsg} "
for b in {0..3};do
for i in {0..9};do
printf " "
sleep .01
done
done
sleep .15;printf "\r${TheMsg} "
done
#printf "\r${TheMsg}\n"
}
#dot. dotdot. dotdotdot.
Elipsis() {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: A wait wheel.\n";return; }
Elipsis_Usage() { printf "\n${RT}Function: ${RO}${FUNCNAME%_*}${RT}\n\n${RT}Purpose:${RT} Text-based wait wheel that grows from one period to three.\n\n\t${RT}Usage: ${RO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
local TheMsg="${1}"
local StrLen=$(echo $TheMsg|sed -E -e 's/\\e[[0-9;]*[a-zA-Z]|\\[Uu][[0-9a-zA-Z]+//g' -e 's/\\n//g'|wc -c)
for e in {0..3};do
[[ $e -eq 0 ]] && printf "${RT}\e[2G${TheMsg}\e[s\e[u\e[${e}C \u2006\r${RT}" || printf "${RT}\e[2G${TheMsg}\e[s\e[u\e[${e}C. \u2006\r${RT}"
sleep .5
done
}
#Double Underline Msg
DULMsg() {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Double underlines the provided string.\n";return; }
local INDENT=
local BOLD=
ARGS=`getopt -o bi: --long bold,indent: -- "$@"`
eval set -- "$ARGS"
while true ; do
case "$1" in
-i|--indent) local INDENT='\e['${2}'G';shift 2;;
-b|--bold) local BOLD='\e[1m';shift 1;;
--) shift;break;;
esac
done
printf "\n${BOLD}${INDENT}"
printf "${@}"
local StrLen=$(($(echo ${@}|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g'|wc -c)-2))
[[ ${@} =~ .*\\n$ || ${@} =~ .*\\n.$ ]] || echo
printf "${BOLD}${INDENT}"
printf '=%.0s' $(seq 0 1 ${StrLen})
printf "${RT}\n\n"
}
#typical pipe-based spinner
ESpinner() {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: A spinner while waiting.\n";return; }
local TheMsg="${1}"
local StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
[[ ${ESINDENT} ]] && local SPINDENT=${ESINDENT} || SPINDENT=$((${StrLen}+5))
local bs=$'\b'
local ThePipes="⋮\u2003${bs} ⋰\u2003${bs} ⋯\u2003${bs} ⋱\u2003${bs}"
for pipe in $ThePipes;do
printf '\e[0m\e[2G'"${TheMsg}"'\e['${SPINDENT}'G\e[0m\e[0;38;5;208m'"${pipe}"'\r\e[0m'
sleep .045
done
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
}
#Spinner using utf-8 characters that are comprised of dots
EDots() {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: A spinner while waiting.\n";return; }
local TheMsg="${1}"
local StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
[[ ${ESINDENT} ]] && local SPINDENT=${ESINDENT} || SPINDENT=$((${StrLen}+5))
local bs=$'\b'
local ThePipes="․ ․ ‥ … ‧ ⁚ ⋮ ∴ ⁖ ∵ ⁘ ∷ ⁙ ⋯ ⋱ ⋮ ⋰ ⋯ ⋱ ⋮ ⋰ ⋯ ⁙ ∷ ⁘ ∴ ⁖ ∵ ⋮ ⁚ ‧ … ‥ ․ ․"
for pipe in $ThePipes;do
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[0;1;38;5;208m${pipe}\u2003${bs}\r\e[0m"
sleep .045
done
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
}
# Draw a box around your message
box-msg() {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Displays a string in a box.\n";return; }
local STR="#####${@}#####";
local StrLen=$(echo "${STR}"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
eval printf "%.3s%.3s%.3s" ╔{1..1} ═{0..$(echo $StrLen)} ╗{1..1}
local END=$(eval printf "%.3s%.3s%.3s" ╔{1..1} ═{0..$(echo $StrLen)} ╗{1..1}|wc -m)
printf '\n║'
local STR=$(echo "${STR}"|tr -d '\n')
local STR=${STR//#/ }
printf " ${STR}\e[${END}G║\n"
eval printf "%.3s%.3s%.3s" ╚{1..1} ═{0..$(echo $StrLen)} ╝{1..1}
printf '\n'
}
#printf a banner
Banner() {
[[ $1 = '--desc' ]] && { printf "${RO}${FUNCNAME}${RT}: Displays a banner.\n";return; }
printf '\n'${RGBRWB}' Text-Fu v'${TEXT-FU_FUNCTIONS_VER}' '${ROW}' '"${@}"' '${RT}'\n'
}
# set starting position for text and fold text into a next uniform block
wrap() {
local DESC="${RO}${FUNCNAME}${RT}: Like fold, but with indents\n"
[[ $1 = '--desc' ]] && { printf "${DESC}";return; }
wrap_usage() {
printf "${DESC}\n"
printf "\e[2GUsage: ${FUNCNAME%%_*} [-i #] [-w #]\n"
printf "\e[4G -i, --indent NUM\e[20GNumber of spaces to indent (default 0)\n"
printf "\e[4G -w, --wrap NUM\e[20GColumn number to wrap text at (default 80)\n"
printf "\n\e[2GEx:\n"
printf "\e[4G <STDOUT>|${FUNCNAME%%_*} -i 5 -w 75 \n"
}
local INDENT=0
local WRAP=80
ARGS=`getopt -o w:i:h -l wrap:,indent:,help -n ${FUNCNAME} -- "$@"`
eval set -- "$ARGS"
while true ; do
case "$1" in
-i|--indent) local INDENT=${2};shift 2;;
-w|--wrap) local WRAP=${2};shift 2;;
-h|--help) ${FUNCNAME}_usage;return 2;;
--) shift;break;;
esac
done
fold -sw $((${WRAP}-${INDENT}))|sed 's/^./'$(printf "\e[${INDENT}G")'&/g'
}
getlinesize() {
local DESC="${RO}${FUNCNAME}${RT}: sets variables LINEW and LINEH for provided string Gives longest string only for multiline"
unset LSTR LINES LINEH LINEW
LINEH=0 LINEW=0
local LSTR=$@
while IFS= read -r L;do LINES+=($(echo "$L"|wc -m));done < <(printf "${LSTR}"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g')
local LINEH=${#LINES[@]}
for i in ${!LINES[@]};do local LINEW=$((${LINES[$i]}>${LINEW}?${LINES[$i]}:${LINEW}));done
unset LINES
}
call-out() {
call-out_usage() { printf '\n\e[1m'${FUNCNAME%_*}':\e[0m Prints text like a callout box\n\n\e[1mUsage:\e[0m '${FUNCNAME%_*}' -x <horizontal offset> -y <vertical offset> -l <length of callout line> <string>\n\n' 1>&2; return; }
local OPTIND o a
while getopts ":x:y:l:h" o; do
case "${o}" in
x) local XOFF="${OPTARG}";;
l) local LINELEN="${OPTARG}";;
y) local YOFF="${OPTARG}";;
h) ${FUNCNAME}_Usage;return 0;;
esac
done
shift "$((OPTIND-1))"
#Everthing after the args is the text for the callout
COSTART=$(getcurpos)
COTEXT="${@}"
[[ ${COTEXT} ]] || COTEXT="\u2000"
COTEXTH=$((printf "${COTEXT}"|wrap -i${COTEXTI} -w${COTEXTW})|wc -l)
COTEXTP=$((($COTEXTH/2)+1))
tput cup 0 0
XOFF=$(($(getcurpos -c)+$XOFF)) && YOFF=$(($(getcurpos -l)+$YOFF))
printf "\e[${YOFF};${XOFF}f"
printf "┬\e[1B\b"
eval printf '%.3s\\e[1B\\b' │{0..$(echo $LINELEN)}
printf '╰'
printf "%.3s" ─{0..3}
printf "┤"
COTEXTC="$(($(getcurpos -l)+1));$(getcurpos -c)"
printf "\e[1D"
COTEXTI=$((${COTEXTC##*;}+4))
COTEXTW=$(($(tput cols)-${COTEXTI}))
COTEXTW=$((${COTEXTW}<=$(tput cols)?${COTEXTW}:$(($(tput cols)-5))))
eval printf '%.3s\\e[1A\\e[1D' │{0..$(echo $COTEXTP)}
printf '╭──';
printf "\e[${COTEXTC}f"
eval printf '%.3s\\e[1B\\e[1D' │{0..$(echo $COTEXTP)}
printf "╰──\e[${COTEXTC}f\e[1B\e[1C"
[[ ${COTEXTP} -eq 1 ]] && COTEXTP=0
printf "\e[${COTEXTP}A$(printf "${COTEXT}"|wrap -i${COTEXTI} -w${COTEXTW})"
printf "\e[${COSTART}f"
}
lxd-cof() {
[[ $1 = '--desc' ]] && { printf "${BO}${FUNCNAME}${RT}: A wait-wheel.\n";return; }
local TheMsg="${1}"
local StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
[[ ${ESINDENT} ]] && local SPINDENT=${ESINDENT} || SPINDENT=$((${StrLen}+5))
scf
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G"
for i in LXDLG LXDDG LXDRG LXDOR LXDLG LXDDG LXDRG LXDOR; do eval "printf \"\$${i}\ue0ff\u2006\"";sleep .15;done
for i in LXDLG LXDDG LXDRG LXDOR LXDLG LXDDG LXDRG LXDOR; do eval "printf \"\$${i}\ue0ff\u2006\"";sleep .15;done
for i in LXDLG LXDDG LXDRG LXDOR LXDLG LXDDG LXDRG LXDOR; do eval "printf \"\$${i}\ue0ff\u2006\e[4D\"";sleep .15;printf "\e[s";done
for i in LXDLG LXDDG LXDRG LXDOR LXDLG LXDDG LXDRG LXDOR; do eval "printf \"\$${i}\ue0ff\u2006\e[4D\"";sleep .15;printf "\e[s";done
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
Sparkles(){
[[ $1 = '--desc' ]] && { printf "${BO}${FUNCNAME}${RT}: A wait wheel of sorts.\n";return; }
declare -a MSG=("¸" "." "•" "\*" "\¨" "\*" "•" "." "¸")
local TheMsg="${1}"
scf
local StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\U2006\e[K\e[0m"
for a in {0..2};do
for b in {0..3};do
for i in {0..8};do
printf "\e[38;5;$((234+${a}+${b}+${i}))m"
printf "${MSG[${i}]/\\/}\e[0m";sleep .01
done
done
sleep .15;printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\U2006\e[K\e[0m"
for b in {0..3};do
for i in {0..9};do
printf " "
sleep .01
done
done
sleep .15;printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\U2006\e[K\e[0m"
done
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
Ball() {
Ball_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} UTF8 wait wheel which uses the Half-Black ball character.\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
local TheMsg="${1}"
local StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local bs=$'\b'
scf
for ball in 0 3 1 2;do
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\u25d${ball}\U2006\e[K\e[0m"
sleep .25
done
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
Clock() {
Clock_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} UTF8 wait wheel that loops through clock characters.\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
local TheMsg="${1}"
local StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local bs=$'\b'
scf
for i in 50 5C 51 5D 52 5E 53 5F 54 60 55 61 56 62 57 63 58 64 59 65 5A 66 5B 67;do
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\U1F5${i}\U2006\e[K\e[0m"
sleep .25
done
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
Dice() {
Dice_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} UTF8 wait wheel that loops through dice characters.\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
local TheMsg="${1}"
StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local bs=$'\b'
scf
for i in {0..5};do
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\u268${i}\U2006\e[K\e[0m"
sleep .45
done
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
Suits() {
Suits_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} UTF8 wait wheel that loops through card suits (i.e. spades, clubs, etc)\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
local TheMsg="${1}"
StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local bs=$'\b'
scf
for suit in 60 63 65 66;do
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G${BR}\u26${suit}\U2006\e[K\e[0m"
sleep .45
done
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
# UTF8 wait wheel which uses the White Pointing Triangle
Triangle() {
Trianlge_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} UTF8 wait wheel that loops through triangle characters.\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
local TheMsg="${1}"
StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local bs=$'\b'
local TheShapes="△${bs} ▷${bs} ▽${bs} ◁${bs}"
scf
for shape in $TheShapes;do
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G${shape}\U2006\e[K\e[0m"
sleep .25
done
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
#A utf8 spinner based on Upper Quadrant Circular Arc
Worm() {
Worm_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} UTF8 wait wheel that loops through \"Upper Quadrant Circular Arc\" characters.\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
local TheMsg="${1}"
StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local bs=$'\b'
local Spacer=0
scf
for i in {1..6};do
local Spacer=$(($Spacer+4))
printf "\e[0m\e[2G${TheMsg}\e[0m\e[$((${SPINDENT}+${Spacer}))G ╭ \e[K\e[0m"
sleep .25
printf "\e[0m\e[2G${TheMsg}\e[0m\e[$((${SPINDENT}+${Spacer}))G ╭╮\e[K\e[0m"
sleep .25
printf "\e[0m\e[2G${TheMsg}\e[0m\e[$((${SPINDENT}+${Spacer}))G ╮\e[K\e[0m"
sleep .25
printf "\e[0m\e[2G${TheMsg}\e[0m\e[$((${SPINDENT}+${Spacer}))G \e[K\e[0m"
sleep .25
done
for i in {1..6};do
local Spacer=$(($Spacer-4))
printf "\e[0m\e[2G${TheMsg}\e[0m\e[$((${SPINDENT}+${Spacer}))G ╮\e[K\e[0m"
sleep .25
printf "\e[0m\e[2G${TheMsg}\e[0m\e[$((${SPINDENT}+${Spacer}))G ╭╮\e[K\e[0m"
sleep .25
printf "\e[0m\e[2G${TheMsg}\e[0m\e[$((${SPINDENT}+${Spacer}))G ╭ \e[K\e[0m"
sleep .25
printf "\e[0m\e[2G${TheMsg}\e[0m\e[$((${SPINDENT}+${Spacer}))G \e[K\e[0m"
sleep .25
done
printf "\e[0m\e[2G${TheMsg}\e[0m\e[K\e[0m"
sco
}
CountDown() {
CountDown_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Displays a message while counting down. Pulls timer duration (in seconds) from wait message\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>\n\nExample: ${FUNCNAME%_*} \"Sleeping for 30 seconds\"\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
local TheMsg="${1}"
local TheMsgClean=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d')
local StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local TheMsgTime=${TheMsgClean//[ a-zA-Z]/}
local NumRegEx='^[0-9]+$'
[[ ${TheMsgTime} =~ $NumRegEx ]] || { printf "\n${BR}Error${BT}: Could not parse CountDown duration.\n\n${BY}Please ensure that the wait message includes a number to represent the duration\n(in seconds) that you want the CountDown to run.${RT}\n\n"; return 3; }
local TheMsgStr1=`echo ${TheMsg}|awk -F"${TheMsgTime}" '{print $1}'`
local TheMsgStr2=`echo ${TheMsg}|awk -F"${TheMsgTime}" '{print $2}'`
local TimeWord="seconds"
for tw in $(seq $TheMsgTime -1 1);do
[[ $tw -eq 1 ]] && printf "\r\t${TheMsgStr1}${tw}${TheMsgStr2} "|sed 's/'"${TimeWord}"'/'"${TimeWord:0:(-1)}"'/g'
[[ $tw -ne 1 ]] && printf "\r\t${TheMsgStr1}${tw}${TheMsgStr2} "
sleep 1
done
TimerResult=$?
printf '\r\e[0m \r\e[0m'
unset tw
return $TimerResult
}
# Wait wheel that has the the little arc (aka worm) jumping and leaving letters
# that eventually spell Ubuntu
Ubuntu() {
Ubuntu_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Wait wheel that spells out Ubuntu\ue0ff\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
scf
local TheMsg="${1}"
StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local Spacer=0
for i in {1..7};do
[[ $i -eq 1 ]] && local Spacer=$((Spacer+1)) || local Spacer=$((${Spacer}+5))
[[ $i -eq 1 ]] && SC='U'
[[ $i -eq 2 ]] && SC='b'
[[ $i -eq 3 ]] && SC='u'
[[ $i -eq 4 ]] && SC='n'
[[ $i -eq 5 ]] && SC='t'
[[ $i -eq 6 ]] && SC='u'
[[ $i -eq 7 ]] && SC='\ue0ff'
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C╭ \e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${CO}${SC}${BT} \e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${CO}${SC}${BT} ╮\e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${CO}${SC}${BT} \e[K\e[0m"
sleep .15
done
sleep .5
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
Canonical() {
Canonical_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Wait wheel that spells out CAN◉NICAL\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
scf
local TheMsg="${1}"
StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local Spacer=0
for i in {1..9};do
[[ $i -eq 1 ]] && local Spacer=$((Spacer+1)) || local Spacer=$((${Spacer}+5))
[[ $i -eq 1 ]] && SC='C'
[[ $i -eq 2 ]] && SC='A'
[[ $i -eq 3 ]] && SC='N'
[[ $i -eq 4 ]] && SC='◉'
[[ $i -eq 5 ]] && SC='N'
[[ $i -eq 6 ]] && SC='I'
[[ $i -eq 7 ]] && SC='C'
[[ $i -eq 8 ]] && SC='A'
[[ $i -eq 9 ]] && SC='L'
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C╭ \e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${BAUB}${SC}${BT}\e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${BAUB}${SC}${BT} ╮\e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${BAUB}${SC}${BT} \e[K\e[0m"
sleep .15
done
sleep .5
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
# Circle of friends logo
Ulogo() {
Ulogo_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Wait wheel combines the Worm wait wheel and the Ubuntu logo \ue0ff\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
scf
local TheMsg="${1}"
StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local Spacer=0
for i in {1..3};do
[[ $i -eq 1 ]] && local Spacer=$((Spacer+1)) || local Spacer=$((${Spacer}+5))
SC='\ue0ff'
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C╭ \e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${CO}${SC}${BT}\e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${CO}${SC}${BT} ╮\e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${CO}${SC}${BT} \e[K\e[0m"
sleep .15
done
sleep .5
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
#Moving Canonical Logo
Clogo() {
Clogo_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Wait wheel combines the Worm wait wheel and the Canonical logo \u25c9\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
scf
local TheMsg="${1}"
StrLen=$(echo "$TheMsg"|sed -E -e 's,\x1B\[[0-9;]*[a-zA-Z],,g;s/^[ \t]*|[ \t]*$//g' -e '/\x1B\[[0]m$/d'|wc -c)
local Spacer=0
for i in {1..3};do
[[ $i -eq 1 ]] && local Spacer=$((Spacer+1)) || local Spacer=$((${Spacer}+5))
SC='\u25c9'
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C╭ \e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${BAUB}${SC}${BT}\e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${BAUB}${SC}${BT} ╮\e[K\e[0m"
sleep .15
printf "\e[0m\e[2G${TheMsg}\e[0m\e[${SPINDENT}G\e[${Spacer}C${BAUB}${SC}${BT} \e[K\e[0m"
sleep .15
done
sleep .5
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
#Function to center Text
CenterText() {
CenterText_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Function to center a text string, performs a CR at end\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<string>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
GetSize
TheMsg=$(printf ${@})
MsgLen=$(echo -n $TheMsg|sed -e 's/\\e[[0-9;]*[a-zA-Z]//g' -e 's/\\n//g' -e's/\\e[[0-9]m//g'|wc -m)
printf "%*s\n" $(((${MYCOLUMNS}/2)+$(($MsgLen/2)))) "$TheMsg"
}
#Function to center text w/o a carriage return
CenterTextNoCR() {
CenterTextNoCR_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Function to center a text string, does not perform a CR at end\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<string>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
GetSize
TheMsg=$(printf "${@}")
MsgLen=$(echo -n $TheMsg|sed -e 's/\\e[[0-9;]*[a-zA-Z]//g' -e 's/\\n//g' -e's/\\e[[0-9]m//g'|wc -m)
printf "\e[$(((${MYCOLUMNS}/2)-$(($MsgLen/2))))G${TheMsg}"
}
#Function to center block of text vertically and horizontally - No Screen clear
CenterBlockHV() {
CenterBlockHV_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Function to horizontally and vertical center a block of text\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<paragraph>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
scf
printf '\e[s'
tput cup 0 0
GetSize
printf '\e[u'
export title=$(printf "$@"|sed 's/'" "'/'"."'/g')
VHEIGHT=$(($(printf "${title}"|wc -l)/2))
export VADJUST=$((${MIDROW}-${VHEIGHT}))
printf "$title"|while read line;do
#printf '\e[2J'
tput cup 0 0
printf '\e['${VADJUST}'B'
LineLen=$(echo -n ${line}|sed -e 's/\\e[[0-9;]*[a-zA-Z]//g' -e 's/\\n//g' -e's/\\e[[0-9]m//g'|wc -m)
#printf "%*s" $(((${MYCOLUMNS}/2)+$LineLen)) "${line//./ }"
#printf '\e['$((${MIDCOL}/2))'G'"${line//./ }"''
COLADJ=$((${MYCOLUMNS}/2))
LINADJ=$((${LineLen}/2))
CURADJ=$((${COLADJ}-${LINADJ}))
line="${line//./\ }"
printf '\e['${CURADJ}'G'"${line}"''
#printf "%*s" $(((${MIDCOL}/2)+$(($LineLen)) "${line}"
VADJUST=$(($VADJUST+1))
done
printf '\n'
sco
}
CenterTextHV() {
CenterTextHV_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Function to horizontally and vertical center a text string\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<string>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
scf
printf '\e[s'
tput cup 0 0
GetSize
printf '\e[u'
line=$(printf "${@}")
LineLen=$(echo -n ${line}|sed -e 's/\\e[[0-9;]*[a-zA-Z]//g' -e 's/\\n//g' -e's/\\e[[0-9]m//g'|wc -m)
export VADJUST=$((${MIDROW}-1))
tput cup 0 0
printf '\e['${VADJUST}'B'
COLADJ=$((${MYCOLUMNS}/2))
LINADJ=$((${LineLen}/2))
CURADJ=$((${COLADJ}-${LINADJ}))
printf '\e['${CURADJ}'G'"${line}"''
#printf "\r%*s" $(((${MYCOLUMNS}/2)+$MsgLen)) $TheMsg
printf '\e[u'
printf '\n'
sco
}
Cylon() {
Cylon_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Wait wheel that builds from left to right\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
local TheMsg="${1}"
[[ -z $TheMsg ]] && local TheMsg="Your Text Here"
MsgLen=$(echo -n $TheMsg|sed -e 's/\\e[[0-9;]*[a-zA-Z]//g' -e 's/\\n//g' -e's/\\e[[0-9]m//g'|wc -m)
local TheMsg=${TheMsg// /_}
scf
CURSTART=$(printf '\e[s')
#for x in {240..255};do
for i in $(seq 232 255);do printf "\e[38;5;${i}m#\e[0m";sleep .03;done
for char in $(echo ${TheMsg}|grep -o .);do [[ ${char} = "_" ]] && printf ' ' || printf ${char};sleep .03;done
for i in $(seq 255 -1 232);do printf "\e[38;5;${i}m#\e[0m";sleep .03;printf "\e[s";done
printf '\e[1G'
for i in $(seq 1 $(($MsgLen+50)));do printf "\e[38;5;${i}m \e[0m";sleep .03;done
#for i in $(seq 255 -1 232);do printf "\e[38;5;${i}m#\e[0m\e[2D";sleep .03;printf "\e[s";done
printf '\e['$(($MsgLen+50))'G'
for i in $(seq 232 1 255);do printf "\e[38;5;${i}m#\e[0m\e[2D";sleep .03;printf "\e[s";done
TheNewMsg=$(for char in $(echo "$TheMsg"|/bin/grep -o .);do printf "$char ";done|awk '{for(i=NF;i>=1;i--) printf "%s", $i;print ""}')
for char in $(echo ${TheNewMsg}|grep -o .);do [[ ${char} = "_" ]] && printf " \e[2D" || printf "${char}\e[2D";sleep .03;printf "\e[s";done
for i in $(seq 255 -1 232);do printf "\e[38;5;${i}m#\e[0m\e[2D";sleep .03;printf "\e[s";done
printf '\e['$(($MsgLen+50))'G'
for i in $(seq 0 1 $(($MsgLen+48)));do printf " \e[2D";sleep .03;printf "\e[s";done
#done
sco
}
CylonCenter() {
local TheMsg="${1}"
[[ -z $TheMsg ]] && local TheMsg="Your Text Here"
MsgLen=$(echo -n $TheMsg|sed -e 's/\\e[[0-9;]*[a-zA-Z]//g' -e 's/\\n//g' -e's/\\e[[0-9]m//g'|wc -m)
FullMsgLen=$(($MsgLen+50))
local TheMsg=${TheMsg// /_}
scf
printf '\e[s'
tput cup 0 0
MYCOLUMNS=$(tput cols)
MYROWS=$(tput lines)
MIDCOL=$(($MYCOLUMNS/3))
MIDROW=$((($MYROWS/2)-1))
printf '\e[u'
export VADJUST=$((${MIDROW}-1))
tput cup 0 0
printf '\e['${VADJUST}'B'
COLADJ=$((${MYCOLUMNS}/2))
LINADJ=$((${FullMsgLen}/2))
CURADJ=$((${COLADJ}-${LINADJ}))
printf '\e['${CURADJ}'G'
for i in $(seq 232 255);do printf "\e[38;5;${i}m#\e[0m";sleep .015;done
for char in $(echo ${TheMsg}|grep -o .);do [[ ${char} = "_" ]] && printf ' ' || printf ${char};sleep .015;done
for i in $(seq 255 -1 232);do printf "\e[38;5;${i}m#\e[0m";sleep .015;printf "\e[s";done
printf '\e['${CURADJ}'G'
for i in $(seq 1 $(($MsgLen+50)));do printf "\e[38;5;${i}m \e[0m";sleep .015;done
#for i in $(seq 255 -1 232);do printf "\e[38;5;${i}m#\e[0m\e[2D";sleep .015;printf "\e[s";done
printf '\e['$((${CURADJ}+$MsgLen+49))'G'
for i in $(seq 232 1 255);do printf "\e[38;5;${i}m#\e[0m\e[2D";sleep .015;printf "\e[s";done
TheNewMsg=$(for char in $(echo "$TheMsg"|/bin/grep -o .);do printf "$char ";done|awk '{for(i=NF;i>=1;i--) printf "%s", $i;print ""}')
for char in $(echo ${TheNewMsg}|grep -o .);do [[ ${char} = "_" ]] && printf " \e[2D" || printf "${char}\e[2D";sleep .015;printf "\e[s";done
for i in $(seq 255 -1 232);do printf "\e[38;5;${i}m#\e[0m\e[2D";sleep .015;printf "\e[s";done
printf '\e['$((${CURADJ}+$MsgLen+50))'G'
for i in $(seq 0 1 $(($MsgLen+50)));do printf " \e[2D";sleep .015;printf "\e[s";done
sco
}
FadeMsg() { TheMsg="${1}"; echo;for i in $(seq 232 255);do printf "\e[38;5;${i}m#\e[0m";sleep .25;done;printf "${TheMsg}";for i in $(seq 255 -1 232);do printf "\e[38;5;${i}m#\e[0m";done;echo; }
FadeIn() { for f in $(seq 232 1 255);do printf '\e[0m\e[2G\e[38;5;'${f}'m'"${@}"'\e[0m';sleep .06;done;unset f; }
FadeOut() { for f in $(seq 255 -1 232);do printf '\e[0m\e[2G\e[38;5;'${f}'m'"${@}"'\e[0m';sleep .06;done;unset f; }
FadeInC() { for f in $(seq 88 6 208);do printf '\e[0m\e[2G\e[38;5;'${f}'m'"${@}"'\e[0m';sleep .20;done;unset f; }
FadeOutC() { for f in $(seq 208 -6 88);do printf '\e[0m\e[2G\e[38;5;'${f}'m'"${@}"'\e[0m';sleep .20;done;unset f; }
Fader() {
Fader_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Wait wheel that fades a message in and out (monochromatic)\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
TheMsg="${@}"
scf
FadeIn "${TheMsg}"
FadeOut "${TheMsg}"
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
Faderc() {
Faderc_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Wait wheel that fades a message in and out of different colors\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<wait msg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
scf
TheMsg="${@}"
FadeInC "${TheMsg}"
FadeOutC "${TheMsg}"
printf "\e[0m\e[2G${TheMsg}\e[K\e[0m"
sco
}
SpinWait() {
#Supported Spinners
SPINNERS='Cylon ESpinner Sparkles EDots Fader Faderc Ulogo Clogo Ubuntu Canonical Suits Ball Dice Clock Elipsis Worm Triangle'
SpinWait_Usage() {
local usage="
${BY}${FUNCNAME%_*}${BT}
${BU}Purpose${BT}
Show a spinner while a processes executes
${BU}Usage${BT}
${FUNCNAME%_*} [OPTIONS] <program to run>
${BU}Options${BT}
${BA}-c:${BT} Comment to display with spinner
${BA}-s:${BT} Spinner type. Valid options are: Spinner, Fader, Faderc Cylon, Ulogo
${BT} Ubuntu, Canonical, Suits, Ball, Dice, Clock, and Elipsis
${BA}-S${BT} Show sample of each spinner
${BA}-l:${BT} Name of logfile (for process that is being called)
\r\e[0m"
printf "\n${usage}\n\n" 2>&1;
}
SpinWait_ShowSpinners() {
SpinWait_ShowSpinners(){ printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Shows various wait wheels\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
scf
for S in ${SPINNERS};do $S 'Showing '${S}' Spinner: ';echo;done
unset S
sco
}
local OPTIND o a
while getopts ":c:s:Sl:h" o; do
case "${o}" in
c) SCOMMENT="${OPTARG}"
;;
s) STYPE="${OPTARG}"
;;
S) ${FUNCNAME}_ShowSpinners
return 0
;;
l) export SLOG="${OPTARG}"
;;
h) ${FUNCNAME}_Usage
return 0
;;
esac
done
[[ $OPTIND -eq 1 ]] && { ${FUNCNAME}_Usage;return; }
#Undocumented use of declare to Capitalize first Letter of string
declare -c STYPE="${STYPE}"
[[ -n $(echo "${SPINNERS}"|grep -o $STYPE) ]] || { printf '\n\n'"${BR}"'Error:'${BT}' Invalid spinner type\n';${FUNCNAME}_Usage;return; }
[[ -n ${SCOMMENT} ]] || SCOMMENT="Please Wait"
shift "$((OPTIND-1))"
#Everthing after the args are processes is the command line we are waiting on
export SPROG="${@}"
#Make sure we can write the log file
[[ -z "${SLOG}" ]] && SLOG=${VOB_LOG_DIR}/VOB.${FUNCNAME}.$$.log
if [[ -n "${SLOG}" ]];then
touch $(dirname "${SLOG}")/foo > /dev/null 2>&1
if [[ $? -eq 0 ]];then
{ rm $(dirname "${SLOG}")/foo > /dev/null 2>&1; }
else
{ printf '\n\n'"${BR}"'Error:'${BT}' Cannot write logfile '"${SLOG}"'\n';unset SLOG; }
fi
fi
scf
SpinnerProg=$(${SPROG} >> ${SLOG} 2>&1) &
pid=$!
trap 'sco; exec 2>&1; kill '$pid' 2>/dev/null; return; ' EXIT
scf
while kill -0 $pid 2>/dev/null;do
$STYPE "${SCOMMENT}"
done
wait $pid
QStatus
trap - EXIT
sco
} 2> /tmp/$FUNCNAME.err.log
setBgHSV() {
setBgHSV_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Helper function for ShowHSVColor and ShowHSVTxt\n\nUsage: NA\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
printf '\e[48;2;%s;%s;%sm' $1 $2 $3
}
setFgHSV() {
setFgHSV_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Helper function for ShowHSVColor and ShowHSVTxt\n\nUsage: NA\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
printf '\e[38;2;%s;%s;%sm' $1 $2 $3
}
resetOutput() {
resetOutput_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Helper function for ShowHSVColor and ShowHSVTxt\n\nUsage: NA\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
echo -en "\e[0m\n"
}
SpectrumColor() {
SpectrumColor_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Helper function for ShowHSVColor and ShowHSVTxt\n\nUsage: NA\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
let h=$1/43
let f=$1-43*$h
let t=$f*255/43
let q=255-t
if [ $h -eq 0 ]
then
echo "255 $t 0"
elif [ $h -eq 1 ]
then
echo "$q 255 0"
elif [ $h -eq 2 ]
then
echo "0 255 $t"
elif [ $h -eq 3 ]
then
echo "0 $q 255"
elif [ $h -eq 4 ]
then
echo "$t 0 255"
elif [ $h -eq 5 ]
then
echo "255 0 $q"
else
# execution should never reach here
echo "0 0 0"
fi
}
SpectrumColorTxt() {
SpectrumColorTxt_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Helper function for ShowHSVColor and ShowHSVTxt\n\nUsage: NA\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
let h=$1/43
let f=$1-43*$h
let t=$f*255/43
let q=255-t
if [ $h -eq 0 ]
then
echo "255 $t 0"
elif [ $h -eq 1 ]
then
echo "$q 255 0"
elif [ $h -eq 2 ]
then
echo "0 255 $t"
elif [ $h -eq 3 ]
then
echo "0 $q 255"
elif [ $h -eq 4 ]
then
echo "$t 0 255"
elif [ $h -eq 5 ]
then
echo "255 0 $q"
else
# execution should never reach here
echo "0 0 0"
fi
}
ShowHSVColor(){
ShowHSVColor_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Shows range of background or foreground colors available in terminal\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<-bg> <-fg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
[[ -z ${1} ]] && { printf '\e[0m\e[1m\nPlease specify -bg (--background) or -fg (--foreground)\e[0m\n\n';return; }
[[ ${1,,} = '-bg' || ${1,,} = '--background' ]] && local CTYPE=Bg
[[ ${1,,} = '-fg' || ${1,,} = '--foreground' ]] && local CTYPE=Fg
for i in `seq 0 255`; do
set${CTYPE}HSV $i 0 0
[[ ${CTYPE} = Bg ]] && echo -en " "
[[ ${CTYPE} = Fg ]] && printf '\u2588'
done
for i in `seq 255 -1 0`; do
set${CTYPE}HSV $i 0 0
[[ ${CTYPE} = Bg ]] && echo -en " "
[[ ${CTYPE} = Fg ]] && printf '\u2588'
done
resetOutput
for i in `seq 0 255`; do
set${CTYPE}HSV 0 $i 0
[[ ${CTYPE} = Bg ]] && echo -n " "
[[ ${CTYPE} = Fg ]] && printf '\u2588'
done
for i in `seq 255 -1 0`; do
set${CTYPE}HSV 0 $i 0
[[ ${CTYPE} = Bg ]] && echo -n " "
[[ ${CTYPE} = Fg ]] && printf '\u2588'
done
resetOutput
for i in `seq 0 255`; do
set${CTYPE}HSV 0 0 $i
[[ ${CTYPE} = Bg ]] && echo -n " "
[[ ${CTYPE} = Fg ]] && printf '\u2588'
done
resetOutput
for i in `seq 255 -1 0`; do
set${CTYPE}HSV 0 0 $i
[[ ${CTYPE} = Bg ]] && echo -n " "
[[ ${CTYPE} = Fg ]] && printf '\u2588'
done
for i in `seq 0 255`; do
set${CTYPE}HSV `SpectrumColor $i`
[[ ${CTYPE} = Bg ]] && echo -n " "
[[ ${CTYPE} = Fg ]] && printf '\u2588'
done
resetOutput
for i in `seq 255 -1 0`; do
set${CTYPE}HSV `SpectrumColor $i`
[[ ${CTYPE} = Bg ]] && echo -n " "
[[ ${CTYPE} = Fg ]] && printf '\u2588'
done
resetOutput
}
ShowHSVTxt(){
ShowHSVTxt_Usage() { printf "\n${BT}Function: ${CO}${FUNCNAME%_*}${RT}\n\n${BY}Purpose:${RT} Shows text value of background or foreground colors available in terminal\n\n\t${BY}Usage: ${CO}${FUNCNAME%_*}${RT} ${RI}<-bg> <-fg>${RT}\n\n" 1>&2;return; }
[[ $1 = '-h' || $1 = '--help' ]] && { ${FUNCNAME}_Usage; return; }
[[ -z ${1} ]] && { printf '\e[0m\e[1m\nPlease specify -bg (--background) or -fg (--foreground)\e[0m\n\n';return; }
[[ ${1,,} = '-bg' || ${1,,} = '--background' ]] && { local CTYPE=Bg; local EC=48; }
[[ ${1,,} = '-fg' || ${1,,} = '--foreground' ]] && { local CTYPE=Fg; local EC=38; }
echo "Reds"
for i in `seq 0 255`; do
set${CTYPE}HSV $i 0 0
echo "\e[${EC};2;${i} 0 0m"|sed 's/ /;/g'
done
echo "Greens"
for i in `seq 0 255`; do
set${CTYPE}HSV 0 $i 0
echo "\e[${EC};2;0 ${i} 0m"|sed 's/ /;/g'
done
echo "Blues"
for i in `seq 0 255`; do
set${CTYPE}HSV 0 0 $i
echo "\e[${EC};2;0 0 ${i}m"|sed 's/ /;/g'
done
resetOutput
for i in `seq 0 255`; do
SC=$(SpectrumColorTxt $i)
set${CTYPE}HSV `SpectrumColorTxt $i`
echo "\e[${EC};2;${SC}m"|sed 's/ /;/g'
unset SC
done
}
red-linefade() {
[[ -n ${1} && ${1} =~ [0-9] ]] && local SPLIT=${1} || local SPLIT=7
scf
for i in `seq 0 ${SPLIT} 255`; do setFgHSV $i 0 0;printf '\u25AC';sleep .015;done;for i in `seq 255 -${SPLIT} 0`; do setFgHSV $i 0 0;printf '\u25AC';sleep .015;done
printf '\r'
for i in `seq 0 ${SPLIT} 255`; do setFgHSV $i 0 0;printf ' ';sleep .010;done;for i in `seq 255 -${SPLIT} 0`; do setFgHSV $i 0 0;printf ' ';sleep .010;done
printf '\e['$(($(seq 0 ${SPLIT} 255|wc -l)*2))'G'
for i in `seq 0 ${SPLIT} 255`; do setFgHSV $i 0 0;printf '\u25AC\e[2D';sleep .015;printf "\e[s";done
printf '\e['$(seq 0 ${SPLIT} 255|wc -l)'G'
for i in `seq 255 -${SPLIT} 0`; do setFgHSV $i 0 0;printf '\u25AC\e[2D';sleep .015;printf "\e[s";done
printf '\e['$(($(seq 0 ${SPLIT} 255|wc -l)*2))'G'
for i in `seq 0 ${SPLIT} 255`; do setFgHSV $i 0 0;printf ' \e[2D';sleep .010;printf "\e[s";done
printf '\e['$(seq 0 ${SPLIT} 255|wc -l)'G'
for i in `seq 255 -${SPLIT} 0`; do setFgHSV $i 0 0;printf ' \e[2D';sleep .010;printf "\e[s";done
sco
}
green-linefade() {
[[ -n ${1} && ${1} =~ [0-9] ]] && local SPLIT=${1} || local SPLIT=7
scf
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 $i 0;printf '\u25AC';sleep .015;done;for i in `seq 255 -${SPLIT} 0`; do setFgHSV 0 $i 0;printf '\u25AC';sleep .015;done
printf '\r'
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 $i 0;printf ' ';sleep .010;done;for i in `seq 255 -${SPLIT} 0`; do setFgHSV 0 $i 0;printf ' ';sleep .010;done
printf '\e['$(($(seq 0 ${SPLIT} 255|wc -l)*2))'G'
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 $i 0;printf '\u25AC\e[2D';sleep .015;printf "\e[s";done
printf '\e['$(seq 0 ${SPLIT} 255|wc -l)'G'
for i in `seq 255 -${SPLIT} 0`; do setFgHSV 0 $i 0;printf '\u25AC\e[2D';sleep .015;printf "\e[s";done
printf '\e['$(($(seq 0 ${SPLIT} 255|wc -l)*2))'G'
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 $i 0;printf ' \e[2D';sleep .010;printf "\e[s";done
printf '\e['$(seq 0 ${SPLIT} 255|wc -l)'G'
for i in `seq 255 -${SPLIT} 0`; do setFgHSV 0 $i 0;printf ' \e[2D';sleep .010;printf "\e[s";done
sco
}
blue-linefade() {
[[ -n ${1} && ${1} =~ [0-9] ]] && local SPLIT=${1} || local SPLIT=7
scf
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 0 $i;printf '\u25AC';sleep .015;done;for i in `seq 255 -${SPLIT} 0`; do setFgHSV 0 0 $i;printf '\u25AC';sleep .015;done
printf '\r'
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 0 $i;printf ' ';sleep .010;done;for i in `seq 255 -${SPLIT} 0`; do setFgHSV 0 0 $i;printf ' ';sleep .010;done
printf '\e['$(($(seq 0 ${SPLIT} 255|wc -l)*2))'G'
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 0 $i;printf '\u25AC\e[2D';sleep .015;printf "\e[s";done
printf '\e['$(seq 0 ${SPLIT} 255|wc -l)'G'
for i in `seq 255 -${SPLIT} 0`; do setFgHSV 0 0 $i;printf '\u25AC\e[2D';sleep .015;printf "\e[s";done
printf '\e['$(($(seq 0 ${SPLIT} 255|wc -l)*2))'G'
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 0 $i;printf ' \e[2D';sleep .010;printf "\e[s";done
printf '\e['$(seq 0 ${SPLIT} 255|wc -l)'G'
for i in `seq 255 -${SPLIT} 0`; do setFgHSV 0 0 $i;printf ' \e[2D';sleep .010;printf "\e[s";done
sco
}
rainbow-line() {
[[ -n ${1} && ${1} =~ [0-9] ]] && local SPLIT=${1} || local SPLIT=7
scf
for i in `seq 0 ${SPLIT} 255`; do setFgHSV `SpectrumColor $i`;printf '\u25AC';sleep .015;done
for i in `seq 0 ${SPLIT} 255`; do setFgHSV `SpectrumColor $i`;printf '\u25AC\e[2D';sleep .015;printf "\e[s";done
sco
}
red-line() {
[[ -n ${1} && ${1} =~ [0-9] ]] && local SPLIT=${1} || local SPLIT=10
scf
for i in `seq 0 ${SPLIT} 255`; do setFgHSV $i 0 0;printf '\u25AC';sleep .05;done
for i in `seq 0 ${SPLIT} 255`; do setFgHSV $i 0 0;printf '\u25AC\e[2D';sleep .05;printf "\e[s";done
sco
}
green-line() {
[[ -n ${1} && ${1} =~ [0-9] ]] && local SPLIT=${1} || local SPLIT=10
scf
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 $i 0;printf '\u25AC';sleep .05;done
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 $i 0;printf '\u25AC\e[2D';sleep .05;printf "\e[s";done
sco
}
blue-line() {
[[ -n ${1} && ${1} =~ [0-9] ]] && local SPLIT=${1} || local SPLIT=10
scf
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 0 $i;printf '\u25AC';sleep .05;done
for i in `seq 0 ${SPLIT} 255`; do setFgHSV 0 0 $i;printf '\u25AC\e[2D';sleep .05;printf "\e[s";done
sco
}
rainbow-cof() {
[[ -n ${1} && ${1} =~ [0-9] ]] && local SPLIT=${1} || local SPLIT=7
scf
for i in `seq 0 ${SPLIT} 255`; do setFgHSV `SpectrumColor $i`;printf '\ue0ff';sleep .05;done
for i in `seq 0 ${SPLIT} 255`; do setFgHSV `SpectrumColor $i`;printf '\ue0ff\e[2D';sleep .05;printf "\e[s";done
sco
}
## End Text attributes and functions ##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment