Skip to content

Commit

Permalink
ui updated in chart of package, arrow of say and spinners status
Browse files Browse the repository at this point in the history
  • Loading branch information
OurCodeBase committed Jan 11, 2024
1 parent 117340e commit f17821a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 45 deletions.
47 changes: 24 additions & 23 deletions src/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ source "${Dir}"/os.sh
# install (str) > install to get package installed size.
# package (str) > takes package (eg: python,nodejs).
# Returns:
# size (int) > Gives you size in MBs.
# size (int) > Gives you size in MiBs.
# Usage:
# pkg.size(dnload,package) > Gives you package file size.
# pkg.size(install,package) > Gives you package installed size.
Expand All @@ -35,14 +35,14 @@ pkg.size(){
return 1;
fi
case "${1}" in
'dnload') local SizeVar="$(apt show "${2}" 2> /dev/null | grep 'Download-Size:')";;
'install') local SizeVar="$(apt show "${2}" 2> /dev/null | grep 'Installed-Size:')";;
'dnload') local SizeSource="$(apt show "${2}" 2> /dev/null | grep 'Download-Size:')";;
'install') local SizeSource="$(apt show "${2}" 2> /dev/null | grep 'Installed-Size:')";;
esac
local Size="$(echo "${SizeVar}" | awk '{print $2}')";
local SizeUnit="$(echo "${SizeVar}" | awk '{print $3}')";
# converting decimals to integers.
local Size="$(echo "${SizeSource}" | awk '{print $2}')";
local SizeUnit="$(echo "${SizeSource}" | awk '{print $3}')";
# convert decimals to integers.
local Size="${Size%%.*}";
# checking unit of package.
# check unit of package.
case "${SizeUnit}" in
'MB') echo "${Size}";;
'kB') echo "$(( Size/1024 ))";;
Expand All @@ -57,22 +57,20 @@ pkg.size(){
# Args:
# pkgs (array) > takes array of packages.
pkg.chart(){
inspect.ScreenSize '96' '12';
inspect.ScreenSize '62' '12';
# this takes all packages as arg.
local ARGs=("${@}");
# total content file size of all packages.
local PuraSizeDL=0;
# total installed size of all packages.
local PuraSizeIN=0;
# turn off cursor.
setCursor off;
echo;
say.success "📦 Getting Information Packages";
echo -e "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ INFORMATION PACKAGES ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃ PACKAGE NAME VERSION DOWNLOAD INSTALLED ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛";
echo -e "
╭─ Packages ─────────────────────────────────────────────╮";
echo -e " │ │";
printf " │ %-25s %-10s %-7s %-7s │\n" 'Package' 'Version' 'DLSize' 'INSize';
printf " │ %-25s %-10s %-7s %-7s │\n" '─────────────────────────' '──────────' '───────' '───────';
for ARG in "${ARGs[@]}"
do
# declare database variable.
Expand All @@ -85,18 +83,21 @@ pkg.chart(){
local PackageSizeDL="$(pkg.size 'dnload' "${ARG}")";
# declare package installed size variable.
local PackageSizeIN="$(pkg.size 'install' "${ARG}")";
printf "${Green}%-13s${Clear} ${Yelo}%10s${Clear} ${Yelo}%-4s${Clear} %-2s ${Yelo}%-4s${Clear} %-2s ┃\n" "${PackageVar}" "${PackageVersion}" "${PackageSizeDL}" "MB" "${PackageSizeIN}" "MB";
echo -e " ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛";
printf "${Green}%-25s${Clear} ${Yelo}%-10s${Clear} ${Yelo}%3s${Clear} %-3s ${Yelo}%3s${Clear} %-3s │\n" "${PackageVar}" "${PackageVersion}" "${PackageSizeDL}" 'MiB' "${PackageSizeIN}" 'MiB';
# Adding dl sizes of all packages.
local PuraSizeDL=$(( PuraSizeDL + PackageSizeDL ));
# Adding ins sizes of all packages.
local PuraSizeIN=$(( PuraSizeIN + PackageSizeIN ));
done
# print total data.
printf " ┃ [ ${Yelo}%5s${Clear} ] ─────────────────────────────────> ${Yelo}%6s${Clear} %-2s ${Yelo}%6s${Clear} %-2s ┃" "TOTAL" "${PuraSizeDL}" "MB" "${PuraSizeIN}" "MB"
echo -e "\n ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛";
echo;
echo -e " │ │";
echo -e " ╰────────────────────────────────────────────────────────╯\n";
echo -e " ╭─ TOTAL ────────────────────╮";
printf " │ %14s: ${Green}%4s${Clear} %3s │\n" "Download Size" "${PuraSizeDL}" 'MiB';
printf " │ %14s: ${Yelo}%4s${Clear} %3s │\n" "Installed Size" "${PuraSizeIN}" 'MiB';
echo -e " ╰────────────────────────────╯";
# turn on cursor.
setCursor on;
# return function.
return;
}

Expand Down Expand Up @@ -128,4 +129,4 @@ pkg.install(){
fi
echo;
return;
}
}
6 changes: 3 additions & 3 deletions src/say.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ _status(){
else local String+="${Uri} ";
fi
done
echo -e "${StatusColor} INFO ${Clear} > ${String}";
echo -e "${StatusColor} INFO ${Clear} ${String}";
return 0;
}

Expand Down Expand Up @@ -108,9 +108,9 @@ say.success(){
# status (int) > takes exit code.
say.checkStatus(){
if [[ "${1}" == 0 ]]; then
echo -e " -> ${StatusGreen} SUCCESS ${Clear}";
echo -e " ${StatusGreen} SUCCESS ${Clear}";
else
echo -e " -> ${StatusRed} FAILED ${Clear}";
echo -e " ${StatusRed} FAILED ${Clear}";
exit 1;
fi
}
42 changes: 23 additions & 19 deletions src/spinner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,33 @@
# run your functions.
# spinner.stop

# Suppressed Variables
if (( 1<2 )); then
# Colors
if (( 2>1 )); then
Clear="\033[0m";
Blue="\033[1;34m";
Genta="\033[1;35m";
Green="\033[1;32m";
Red="\033[1;31m";
Yelo="\033[1;33m";
fi

# Global Variables
if (( 2>1 )); then
icon="";
success="SUCCESS";
error="FAILED";
Gora="\033[1;97m"
# BG Colors.
BGRed="\033[1;41m";
BGGreen="\033[1;42m";
BGYelo="\033[1;43m";
# Status Colors.
StatusRed="${BGRed}${Gora}";
StatusGreen="${BGGreen}${Gora}";
StatusYelo="${BGYelo}${Gora}";
CircleIcon="";
Success="SUCCESS";
Failure="FAILED";
list=(
"${Blue}${icon}${Green}${icon}${Yelo}${icon}${Red}${icon}${Genta}${icon} "
" ${Green}${icon}${Yelo}${icon}${Red}${icon}${Genta}${icon}${Blue}${icon} "
" ${Red}${icon}${Genta}${icon}${Yelo}${icon}${Blue}${icon}${Green}${icon} "
" ${Genta}${icon}${Blue}${icon}${Green}${Yelo}${icon}${icon}${Red}${icon} "
" ${Blue}${icon}${Green}${icon}${Red}${icon}${Yelo}${icon}${Genta}${icon}"
"${Blue}${CircleIcon}${Green}${CircleIcon}${Yelo}${CircleIcon}${Red}${CircleIcon}${Genta}${CircleIcon} "
" ${Green}${CircleIcon}${Yelo}${CircleIcon}${Red}${CircleIcon}${Genta}${CircleIcon}${Blue}${CircleIcon} "
" ${Red}${CircleIcon}${Genta}${CircleIcon}${Yelo}${CircleIcon}${Blue}${CircleIcon}${Green}${CircleIcon} "
" ${Genta}${CircleIcon}${Blue}${CircleIcon}${Green}${Yelo}${CircleIcon}${CircleIcon}${Red}${CircleIcon} "
" ${Blue}${CircleIcon}${Green}${CircleIcon}${Red}${CircleIcon}${Yelo}${CircleIcon}${Genta}${CircleIcon}"
)
fi

Expand Down Expand Up @@ -57,14 +63,13 @@ _spinner(){
exit 1
fi
kill ${3} > /dev/null 2>&1
echo -en "\b${Clear} -> ["
echo -en "\b${Clear} "
if [[ $2 -eq 0 ]]; then
echo -en " ${Green}${success}${Clear} "
echo -e "${StatusGreen} ${Success} ${Clear}"
else
echo -en " ${Red}${error}${Clear} "
echo -e "${StatusRed} ${Failure} ${Clear}"
exit 1;
fi
echo -e "${Clear}]"
;;
*)
echo "error: invalid args, try again with {start/stop}"
Expand All @@ -86,7 +91,6 @@ spinner.start(){
return 1;
fi
local uri="${1} '${Green}${2}${Clear}'..."
# required cmds.
spinner.setCursor off
_spinner start "${uri}" &
_spinner_pid="${!}"
Expand All @@ -99,4 +103,4 @@ spinner.stop(){
_spinner stop ${?} ${_spinner_pid};
unset ${_spinner_pid};
spinner.setCursor on
}
}

0 comments on commit f17821a

Please sign in to comment.