summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2023-02-02 10:42:59 +0000
committerdavidovski <david@davidovski.xyz>2023-05-17 16:52:12 +0000
commit53e854ffc351785c029ed610902b979572beeb80 (patch)
tree36dbb3675bdf25c6dbb3dfa486c301166fb343bf
parent7c764a03a491edf85c2aed8f5108f64b9f5a8d87 (diff)
Fix hbar with no arguments
-rwxr-xr-xsrc/util/hbar.sh29
-rwxr-xr-xtest/hbar.sh14
2 files changed, 28 insertions, 15 deletions
diff --git a/src/util/hbar.sh b/src/util/hbar.sh
index 603f66a..502bdc1 100755
--- a/src/util/hbar.sh
+++ b/src/util/hbar.sh
@@ -3,12 +3,12 @@
. /usr/lib/xilib.sh
move_up () {
- [ ! "$1" = "-1" ] &&
+ [ ! "$1" = "0" ] &&
printf "\033[%dA" "$1" "0"
}
move_down () {
- [ ! "$1" = "-1" ] &&
+ [ ! "$1" = "0" ] &&
printf "\033[%dB" "$1"
}
@@ -21,7 +21,7 @@ count_string () {
c=$1
t=$2
}
- printf "[%s%s/%s%s]" $c $unit $t $unit
+ printf "[%s/%s]" $c $t
}
hbar () {
@@ -58,11 +58,11 @@ hbar () {
;;
esac
done
+
shift $((OPTIND-1))
[ "$#" -lt 2 ] && {
- printf "$RESET\n"
- exit 1
+ return 1
}
completed="$1"
@@ -71,7 +71,7 @@ hbar () {
move_up $line
count=$(count_string $completed $total)
- printf "\r$text"
+ #printf "\r$text"
printf "$RESET\r"
printf "$color"
@@ -86,16 +86,27 @@ hbar () {
printf "%s" "${text%%${text#?}}"
text="${text#?}"
} || {
- printf " "
+ [ "$((width-${#count}))" = "$i" ] && {
+ printf "%s" "${count%%${count#?}}"
+ count="${count#?}"
+ } || {
+ printf " "
+ }
}
i=$((i+1))
done
move_down $line
- $terminate && printf "$RESET\n"
+ printf "$RESET"
+ $terminate && printf "\n"
exit 0
}
-printf "%s" "$(hbar "$@")"
+[ "$#" -eq "0" ] && {
+ printf "$RESET\n"
+ exit 0
+}
+
+printf "$(hbar "$@")"
diff --git a/test/hbar.sh b/test/hbar.sh
index 6eaaa55..eada165 100755
--- a/test/hbar.sh
+++ b/test/hbar.sh
@@ -17,27 +17,29 @@ sleep 1
TEXT="Hello there"
-${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX
for x in $(seq $MAX); do
${HBAR} -T "${TEXT}" -u ${UNIT} $x $MAX
#sleep 0.01
done
${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX
+echo "world"
+
sleep 1
clear
echo Doing 2 bars at the same time
sleep 1
-hbar
+${HBAR}
+sleep 1
for x in $(seq $MAX); do
${HBAR} -l 0 -T "${TEXT}" $((MAX - x)) $MAX
${HBAR} -l 1 -T "${TEXT}" $x $MAX
done
-${HBAR} -l 1 -T "${TEXT}" $x $MAX
-${HBAR} -l 0 -t -T "${TEXT}" $((MAX-x)) $MAX
+${HBAR} -l 0 -t -T "${TEXT}" $x $MAX
+${HBAR} -l 1 -t -T "${TEXT}" $((MAX-x)) $MAX
-MAX=20000000
+MAX=2000000
sleep 1
clear
@@ -45,6 +47,6 @@ echo Doing long bar
sleep 1
for x in $(seq 0 991 $MAX); do
- ${HBAR} -h -T "${TEXT}" $x $MAX
+ ${HBAR} -h -T "${TEXT}" $((x*1000000)) $((MAX*1000000))
done
${HBAR} -ht -T "${TEXT}" $x $MAX