added new formatting and a demo script
This commit is contained in:
parent
faa371fc48
commit
1ea5d40c07
2 changed files with 131 additions and 11 deletions
107
demo.sh
Normal file
107
demo.sh
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Initial Vars
|
||||||
|
VERSION=1.0.0
|
||||||
|
scriptname="${0##*/}"
|
||||||
|
rundir="${0%/*}"
|
||||||
|
runuser="$(whoami)"
|
||||||
|
pretty_date="$(date +%Y-%m-%d_%H-%M-%S)"
|
||||||
|
|
||||||
|
source ${rundir}/functions
|
||||||
|
|
||||||
|
# Title
|
||||||
|
clear
|
||||||
|
boxborder \
|
||||||
|
"Pyr0ball's Bash Functions Library Demo v${VERSION}" \
|
||||||
|
"functions v${functionsrev}"
|
||||||
|
#boxborder
|
||||||
|
|
||||||
|
# Colorized output
|
||||||
|
boxborder \
|
||||||
|
"${lyl}Text Formatting${dfl}" \
|
||||||
|
$(boxseparator) \
|
||||||
|
"${red}Red Text Sample${dfl}" \
|
||||||
|
"${lrd}Light Red Text${dfl}" \
|
||||||
|
"${ong}Orange Text Sample${dfl}" \
|
||||||
|
"${ylw}Yellow Text Sample${dfl}" \
|
||||||
|
"${lyl}Light Yellow Text${dfl}" \
|
||||||
|
"${grn}Green Text Sample${dfl}" \
|
||||||
|
"${cyn}Cyan Text Sample${dfl}" \
|
||||||
|
"${lbl}Light Blue Text${dfl}" \
|
||||||
|
"${blu}Blue Text Sample${dfl}" \
|
||||||
|
"${pur}Purple Text Sample${dfl}" \
|
||||||
|
"${mag}Magenta Text Sample${dfl}" \
|
||||||
|
"${gry}Grey Text Sample${dfl}" \
|
||||||
|
$(boxseparator) \
|
||||||
|
"${bld}Bold Text Sample${dfl}" \
|
||||||
|
"${dim}Dim Text Sample${dfl}" \
|
||||||
|
"${unl}Underline Text${dfl}" \
|
||||||
|
"${inv}Inverted Text Sample${dfl}" \
|
||||||
|
"Default Text Sample" \
|
||||||
|
$(boxseparator) \
|
||||||
|
"${lyl}Combined Text Formatting${dfl}" \
|
||||||
|
"${red}${bld}Red + Bold Text${dfl}" \
|
||||||
|
"${red}${dim}Red + Dim Text${dfl}" \
|
||||||
|
"${red}${unl}Red + Underline${dfl}" \
|
||||||
|
"${red}${inv}Red + Inverted${dfl}"
|
||||||
|
# boxborder
|
||||||
|
echo ""
|
||||||
|
boxborder "${lyl}Bounding Boxes${dfl}"
|
||||||
|
box-double
|
||||||
|
boxborder "Double Line"
|
||||||
|
box-heavy
|
||||||
|
boxborder "Heavy"
|
||||||
|
box-light
|
||||||
|
boxborder "Light"
|
||||||
|
box-rounded
|
||||||
|
boxborder "Rounded"
|
||||||
|
box-singlechar
|
||||||
|
boxborder "Single Character"
|
||||||
|
box-norm
|
||||||
|
boxborder "Normal"
|
||||||
|
|
||||||
|
boxborder \
|
||||||
|
"${lyl}Keyboard Interactive Menus${dfl}"\
|
||||||
|
$(boxseparator) \
|
||||||
|
"Use Up/Down arrow keys, or [j|k] to navigate" \
|
||||||
|
"For Multiselect, use space bar to invert selection" \
|
||||||
|
"and 'Enter' to Confirm"
|
||||||
|
#boxborder
|
||||||
|
|
||||||
|
# Example for select_option
|
||||||
|
echo "Select one option using up/down keys and enter to confirm:"
|
||||||
|
echo
|
||||||
|
|
||||||
|
options=("one" "two" "three")
|
||||||
|
|
||||||
|
select_option "${options[@]}"
|
||||||
|
choice=$?
|
||||||
|
|
||||||
|
echo "Choosen index = $choice"
|
||||||
|
echo " value = ${options[$choice]}"
|
||||||
|
|
||||||
|
# Examples for above select_opt
|
||||||
|
case `select_opt "Yes" "No" "Cancel"` in
|
||||||
|
0) echo "selected Yes";;
|
||||||
|
1) echo "selected No";;
|
||||||
|
2) echo "selected Cancel";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
options=("Yes" "No" "${array[@]}") # join arrays to add some variable array
|
||||||
|
case `select_opt "${options[@]}"` in
|
||||||
|
0) echo "selected Yes";;
|
||||||
|
1) echo "selected No";;
|
||||||
|
*) echo "selected ${options[$?]}";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Example for above multiselect functions
|
||||||
|
my_options=( "Option 1" "Option 2" "Option 3" )
|
||||||
|
preselection=( "true" "true" "false" )
|
||||||
|
|
||||||
|
multiselect result my_options preselection
|
||||||
|
|
||||||
|
idx=0
|
||||||
|
for option in "${my_options[@]}"; do
|
||||||
|
echo -e "$option\t=> ${result[idx]}"
|
||||||
|
((idx++))
|
||||||
|
done
|
||||||
35
functions
35
functions
|
|
@ -2,6 +2,7 @@
|
||||||
# pyr0ball script functions library
|
# pyr0ball script functions library
|
||||||
|
|
||||||
# Initial Vars
|
# Initial Vars
|
||||||
|
functionsrev=1.0.1
|
||||||
scriptname="${0##*/}"
|
scriptname="${0##*/}"
|
||||||
rundir="${0%/*}"
|
rundir="${0%/*}"
|
||||||
runuser="$(whoami)"
|
runuser="$(whoami)"
|
||||||
|
|
@ -17,8 +18,10 @@ ESC=$( printf "\033")
|
||||||
# options are "single" "double" "char"
|
# options are "single" "double" "char"
|
||||||
# for the "char" option, change the "borderchar" variable to
|
# for the "char" option, change the "borderchar" variable to
|
||||||
# whichever unicode character you wish to use
|
# whichever unicode character you wish to use
|
||||||
boxtype="${boxtype:='single'}" # Sets default 'single' if not already set
|
# boxtype="${boxtype:-single}" # Sets default 'single' if not already set
|
||||||
borderchar="${borderchar:='#'}" # Sets default '#' if not already set
|
# borderchar="${borderchar:-#}" # Sets default '#' if not already set
|
||||||
|
boxtype="norm" # Sets default 'single' if not already set
|
||||||
|
borderchar="#" # Sets default '#' if not already set
|
||||||
|
|
||||||
# Colorization options
|
# Colorization options
|
||||||
if [[ "$TERM" != "linux" ]] ; then
|
if [[ "$TERM" != "linux" ]] ; then
|
||||||
|
|
@ -33,13 +36,21 @@ if [[ "$TERM" != "linux" ]] ; then
|
||||||
ong=$(echo -e "${ESC}[38;5;166m") # orange
|
ong=$(echo -e "${ESC}[38;5;166m") # orange
|
||||||
lyl=$(echo -e "${ESC}[38;5;228m") # light yellow
|
lyl=$(echo -e "${ESC}[38;5;228m") # light yellow
|
||||||
lrd=$(echo -e "${ESC}[38;5;196m") # light red
|
lrd=$(echo -e "${ESC}[38;5;196m") # light red
|
||||||
gry=$(echo -e "${ESC}[38;5;238m") # Grey
|
gry=$(echo -e "${ESC}[38;5;240m") # Grey
|
||||||
norm=$(echo -e "${ESC}[38;5;9m") # default/normal
|
norm=$(echo -e "${ESC}[39m") # default/normal
|
||||||
#
|
#
|
||||||
bld=$(echo -e "${ESC}[1m") # bold
|
bld=$(echo -e "${ESC}[1m") # bold
|
||||||
|
unb=$(echo -e "${ESC}[21m") # un-bold
|
||||||
|
dim=$(echo -e "${ESC}[2m") # dim
|
||||||
|
und=$(echo -e "${ESC}[22m") # un-dim
|
||||||
unl=$(echo -e "${ESC}[4m") # underline
|
unl=$(echo -e "${ESC}[4m") # underline
|
||||||
blk=$(echo -e "${ESC}[7m") # blinking not supported in our xterm, so reverse instead
|
|
||||||
nln=$(echo -e "${ESC}[24") # not-underline
|
nln=$(echo -e "${ESC}[24") # not-underline
|
||||||
|
blk=$(echo -e "${ESC}[5") # blinking
|
||||||
|
unbl=$(echo -e "${ESC}[25") # stop blinking
|
||||||
|
inv=$(echo -e "${ESC}[7m") # invert
|
||||||
|
rsinv=$(echo -e "${ESC}[27") # reset invert
|
||||||
|
hid=$(echo -e "${ESC}[8") # hidden
|
||||||
|
unh=$(echo -e "${ESC}[28") # unhide
|
||||||
dfl=$(echo -e "${ESC}[0m") # restore default
|
dfl=$(echo -e "${ESC}[0m") # restore default
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -49,7 +60,7 @@ enter_arrow=$(echo -e '\u21B5')
|
||||||
green_check=${grn}$(echo -e '\u2714')${dfl}
|
green_check=${grn}$(echo -e '\u2714')${dfl}
|
||||||
red_x=${lrd}$(echo -e '\u00D7')${dfl}
|
red_x=${lrd}$(echo -e '\u00D7')${dfl}
|
||||||
selected_opt=$(echo -e '\u25C9')
|
selected_opt=$(echo -e '\u25C9')
|
||||||
deselected_opt=$(echo -e '\u25CB')
|
deselected_opt=$(echo -e '\u25CE')
|
||||||
|
|
||||||
# For drawing pretty boxes
|
# For drawing pretty boxes
|
||||||
terminal_width=$(tput cols)
|
terminal_width=$(tput cols)
|
||||||
|
|
@ -69,7 +80,7 @@ double_v=$(echo -e '\u2551')
|
||||||
|
|
||||||
|
|
||||||
# Box border type single-line
|
# Box border type single-line
|
||||||
box-single(){
|
box-norm(){
|
||||||
# ---------------------------------------#
|
# ---------------------------------------#
|
||||||
top_border=${norm_h}
|
top_border=${norm_h}
|
||||||
bottom_border=${norm_h}
|
bottom_border=${norm_h}
|
||||||
|
|
@ -99,7 +110,7 @@ box-double(){
|
||||||
}
|
}
|
||||||
|
|
||||||
# Box border type thick-line
|
# Box border type thick-line
|
||||||
box-thicc(){
|
box-heavy(){
|
||||||
# ---------------------------------------#
|
# ---------------------------------------#
|
||||||
top_border=$(echo -e '\u2580')
|
top_border=$(echo -e '\u2580')
|
||||||
bottom_border=$(echo -e '\u2584')
|
bottom_border=$(echo -e '\u2584')
|
||||||
|
|
@ -114,7 +125,7 @@ box-thicc(){
|
||||||
}
|
}
|
||||||
|
|
||||||
# Box border type thin-line
|
# Box border type thin-line
|
||||||
box-thin(){
|
box-light(){
|
||||||
# ---------------------------------------#
|
# ---------------------------------------#
|
||||||
#top_border=$(echo -e '\u23BA')
|
#top_border=$(echo -e '\u23BA')
|
||||||
top_border=${light_h}
|
top_border=${light_h}
|
||||||
|
|
@ -157,7 +168,7 @@ box-singlechar(){
|
||||||
# ---------------------------------------#
|
# ---------------------------------------#
|
||||||
}
|
}
|
||||||
|
|
||||||
set-boxtype(){
|
# set-boxtype(){
|
||||||
case $boxtype in
|
case $boxtype in
|
||||||
norm) box-norm ;;
|
norm) box-norm ;;
|
||||||
double) box-double ;;
|
double) box-double ;;
|
||||||
|
|
@ -166,7 +177,9 @@ set-boxtype(){
|
||||||
rounded) box-rounded ;;
|
rounded) box-rounded ;;
|
||||||
char) box-singlechar ;;
|
char) box-singlechar ;;
|
||||||
esac
|
esac
|
||||||
}
|
# }
|
||||||
|
|
||||||
|
#set-boxtype
|
||||||
|
|
||||||
repchar() {
|
repchar() {
|
||||||
n=1
|
n=1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue