Skip to content

Commit

Permalink
is online, standard output
Browse files Browse the repository at this point in the history
  • Loading branch information
lazypwny751 committed Sep 12, 2022
1 parent e7a82ab commit d67c1c6
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 6 deletions.
23 changes: 20 additions & 3 deletions lib/bash-5.1.16/check.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
#!/bin/bash

check:have:specialchar() {
if ! [[ "${1}" =~ ['!@#$%^&*()_+.,~;£{}?= '] ]] ; then
if [[ "${1}" =~ ['\[!@#$ %^&*()+|?{}"=,;/£½'] ]] ; then
return 1
elif [[ "${1}" =~ "'" ]] ; then
return 1
elif [[ "${1}" = *"]"* ]] ; then
return 1
else
return 0
fi
}

check:is:online() {
if command -v "ping" &> /dev/null ; then
if ping -c 1 -q google.com &>/dev/null ; then
return 0
else
return 1
fi
else
echo -e "\t${0##*/}: command: ping not found."
return 1
fi
}
Expand Down Expand Up @@ -57,7 +74,7 @@ check:is:root() {
fi
}

opshelper:is:arch() {
check:is:arch() {
local i="" status="false"

if [[ "${#}" -ge "1" ]] ; then
Expand Down Expand Up @@ -98,4 +115,4 @@ check:compare:version() {
else
return 2 # <,?
fi
}
}
128 changes: 125 additions & 3 deletions lib/bash-5.1.16/userinterface.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,131 @@
#!/bin/bash

userinterface:question() {
:
local input="" text="sure?[y/N]:> " true="[yY]"

while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
--[tT][eE][xX][tT]|-[tT][eE])
shift
if [[ -n "${1}" ]] ; then
local text="${1}"
shift
fi
;;
--[tT][rR][uU][eE]|-[tT][rR])
shift
if [[ -n "${1}" ]] ; then
local true="${1}"
shift
fi
;;
*)
shift
;;
esac
done

read -p "${text}" input
case "${input}" in
${true})
return 0
;;
*)
return 1
;;
esac

}

userinterface:spinner() {
:
userinterface:spinner:line() {
local count="0" total="34" sleep="0.5" pstr="[=======================================================================]"

while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
--[cC][oO][uU][nN][tT]|-[cC])
shift
if [[ -n "${1}" ]] ; then
local count="${1}"
shift
fi
;;
--[tT][oO][tT][aA][lL]|-[tT])
shift
if [[ -n "${1}" ]] ; then
local total="${1}"
shift
fi
;;
--[sS][lL][eE][eE][pP]|-[sS])
shift
if [[ -n "${1}" ]] ; then
local sleep="${1}"
shift
fi
;;
*)
shift
;;
esac
done

while [ $count -lt $total ]; do
sleep "${sleep}" # this is work
count=$(( $count + 1 ))
pd=$(( $count * 73 / $total ))
printf "\r%3d.%1d%% %.${pd}s" $(( $count * 100 / $total )) $(( ($count * 1000 / $total) % 10 )) $pstr
done
}

userinterface:output() {
local text="sample output text from ${0##*/}:${FUNCNAME}" TYPE="success"
while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
--[tT][eE][xX][tT]|-[tT])
shift
if [[ -n "${1}" ]] ; then
local text="${1}"
shift
fi
;;
--[sS][uU][cC][cC][eE][sS][sS]|-[sS])
shift
local TYPE="success"
;;
--[eE][rR][rR][oO][rR]|-[eE])
shift
local TYPE="error"
;;
--[iI][nN][fF][oO]|-[iI])
shift
local TYPE="info"
;;
--[tT][yY][pP][eE]|-[tT])
shift
if [[ -n "${1}" ]] ; then
local TYPE="${1}"
shift
fi
;;
*)
shift
;;
esac
done

case "${TYPE}" in
success)
echo -e "\t${0##*/}: \033[0;32mSUCCESS\033[0m: ${text}\033[0m"
;;
error)
echo -e "\t${0##*/}: \033[0;31mERROR\033[0m: ${text}\033[0m"
return 1
;;
info)
echo -e "\t${0##*/}: \033[0;34mINFO\033[0m: ${text}\033[0m"
;;
*)
echo -e "\t${0##*/}: ${FUNCNAME}: ${TYPE}: ${text}"
;;
esac
}

0 comments on commit d67c1c6

Please sign in to comment.