summaryrefslogtreecommitdiff
path: root/src/util/hbar.sh
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2026-10-01 10:34:33 +0100
committerdavidovski <david@davidovski.xyz>2026-10-01 10:34:33 +0100
commiteca55e60c29440c4e2e007b54ea1a1983e965954 (patch)
treea98173c09f69864cc25395bfdab67d682434854b /src/util/hbar.sh
parentf20bd9d6369c2e1246dcdd4af26b085da99c18e0 (diff)
Add libhbar to shmkHEADmaster
Diffstat (limited to 'src/util/hbar.sh')
-rwxr-xr-xsrc/util/hbar.sh104
1 files changed, 1 insertions, 103 deletions
diff --git a/src/util/hbar.sh b/src/util/hbar.sh
index 9518e66..230ff5d 100755
--- a/src/util/hbar.sh
+++ b/src/util/hbar.sh
@@ -1,108 +1,6 @@
#!/bin/mksh -U
-#include colors
-#include xilib
-move_up () {
- [ ! "$1" = "0" ] &&
- printf "\033[%dA" "$1" "0"
-}
-
-move_down () {
- [ ! "$1" = "0" ] &&
- printf "\033[%dB" "$1"
-}
-
-count_string () {
- local c t
- $human && {
- c=$(format_bytes $completed)
- t=$(format_bytes $total)
- } || {
- c=$1
- t=$2
- }
- printf "[%s/%s]" $c $t
-}
-
-hbar () {
- local width terminate human text color reset unit line count
- width=$(tput cols)
- color="$BLACK$BG_WHITE"
- reset="$WHITE$BG_DEFAULT"
- terminate=false
- human=false
- line=0
-
- while getopts "T:c:r:u:l:ht" opt; do
- case "$opt" in
- T)
- text="$OPTARG"
- ;;
- c)
- color="$OPTARG"
- ;;
- r)
- reset="$OPTARG"
- ;;
- u)
- unit="$OPTARG"
- ;;
- t)
- terminate=true
- ;;
- h)
- human=true
- ;;
- l)
- line="$OPTARG"
- ;;
- esac
- done
-
- shift $((OPTIND-1))
-
- [ "$#" -lt 2 ] && {
- return 1
- }
-
- completed="$1"
- total="$2"
-
- move_up $line
-
- count=$(count_string $completed $total)
- #printf "\r$text"
- printf "$RESET\r"
- printf "$color"
-
- reset_at=0
- [ "$total" -gt "0" ] && reset_at=$(((completed*width)/total))
-
- i=0
- while [ "$i" -lt "$width" ]; do
- [ "$i" = "$reset_at" ] && printf "$reset"
-
- [ "${#text}" -gt 0 ] && {
- printf "%s" "${text%%${text#?}}"
- text="${text#?}"
- } || {
- [ "$((width-${#count}))" = "$i" ] && {
- printf "%s" "${count%%${count#?}}"
- count="${count#?}"
- } || {
- printf " "
- }
- }
- i=$((i+1))
- done
-
- move_down $line
-
- printf "$RESET"
- $terminate && printf "\n"
-
- exit 0
-}
+#include libhbar
[ "$#" -eq "0" ] && {
printf "$RESET\n"