summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2022-10-06 08:48:04 +0100
committerdavidovski <david@davidovski.xyz>2022-10-06 08:48:04 +0100
commit6fa20f922dafaa9615214a3c6913c270db3ec3b6 (patch)
tree0d561caea55400e498e1cc78b8fdd2dbf1bd9c7f
parent91f3e7f0342ee77cb3134e030e92003c59f2d1f0 (diff)
Fixed hbar printing issue
-rwxr-xr-xsrc/util/hbar.sh18
-rwxr-xr-xtest/hbar.sh17
2 files changed, 27 insertions, 8 deletions
diff --git a/src/util/hbar.sh b/src/util/hbar.sh
index 25343bd..603f66a 100755
--- a/src/util/hbar.sh
+++ b/src/util/hbar.sh
@@ -1,5 +1,6 @@
#!/bin/sh
. /usr/lib/colors.sh
+. /usr/lib/xilib.sh
move_up () {
[ ! "$1" = "-1" ] &&
@@ -8,7 +9,7 @@ move_up () {
move_down () {
[ ! "$1" = "-1" ] &&
- printf "\033[%dA" "$1"
+ printf "\033[%dB" "$1"
}
count_string () {
@@ -26,13 +27,13 @@ count_string () {
hbar () {
local width terminate human text color reset unit line count
width=$(tput cols)
- color=$BG_BLUE
- reset=$BG_DEFAULT
+ color="$BLACK$BG_WHITE"
+ reset="$WHITE$BG_DEFAULT"
terminate=false
human=false
line=0
- while getopts ":T:c:r:u:l:ht" opt; do
+ while getopts "T:c:r:u:l:ht" opt; do
case "$opt" in
T)
text="$OPTARG"
@@ -81,7 +82,12 @@ hbar () {
while [ "$i" -lt "$width" ]; do
[ "$i" = "$reset_at" ] && printf "$reset"
- printf " "
+ [ "${#text}" -gt 0 ] && {
+ printf "%s" "${text%%${text#?}}"
+ text="${text#?}"
+ } || {
+ printf " "
+ }
i=$((i+1))
done
@@ -92,4 +98,4 @@ hbar () {
exit 0
}
-hbar $@
+printf "%s" "$(hbar "$@")"
diff --git a/test/hbar.sh b/test/hbar.sh
index 4a124f2..6eaaa55 100755
--- a/test/hbar.sh
+++ b/test/hbar.sh
@@ -10,6 +10,11 @@ for x in $(seq $MAX); do
#sleep 0.01
done
+sleep 1
+clear
+echo Doing hello there bar
+sleep 1
+
TEXT="Hello there"
${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX
@@ -19,19 +24,27 @@ for x in $(seq $MAX); do
done
${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX
+sleep 1
+clear
+echo Doing 2 bars at the same time
+sleep 1
+
hbar
for x in $(seq $MAX); do
${HBAR} -l 0 -T "${TEXT}" $((MAX - x)) $MAX
${HBAR} -l 1 -T "${TEXT}" $x $MAX
- #sleep 0.01
done
${HBAR} -l 1 -T "${TEXT}" $x $MAX
${HBAR} -l 0 -t -T "${TEXT}" $((MAX-x)) $MAX
MAX=20000000
+sleep 1
+clear
+echo Doing long bar
+sleep 1
+
for x in $(seq 0 991 $MAX); do
${HBAR} -h -T "${TEXT}" $x $MAX
- #sleep 0.01
done
${HBAR} -ht -T "${TEXT}" $x $MAX