From 3ff00bc74d5a99bac8037a1954d6c2104e7f777b Mon Sep 17 00:00:00 2001 From: davidovski Date: Sat, 21 Jan 2023 12:59:59 +0000 Subject: Fix issues wth xitui not showing text --- src/lib/xilib.sh | 12 ++++++++++++ src/lib/xitui.sh | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/xilib.sh b/src/lib/xilib.sh index 57dd10c..5c662a9 100644 --- a/src/lib/xilib.sh +++ b/src/lib/xilib.sh @@ -32,3 +32,15 @@ reverse_lines () { } +#!/bin/sh + +basename () { + name=$1 + suf=$2 + pre=${name%/*} + name=${name#$pre/} + + echo ${name#$suf} +} + +basename diff --git a/src/lib/xitui.sh b/src/lib/xitui.sh index bd23bdc..f47adb3 100644 --- a/src/lib/xitui.sh +++ b/src/lib/xitui.sh @@ -359,7 +359,8 @@ t_input () { t_msg "$@ >" > $(tty) - t_yes_cu + stty echo + t_yes_cur read var t_set_tty t_no_cur -- cgit v1.2.1 From ef46bc163713c6da7693c85368dc0c23ed4b4ed4 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sat, 21 Jan 2023 13:00:14 +0000 Subject: Remove basename extra from xilib --- src/lib/xilib.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/xilib.sh b/src/lib/xilib.sh index 5c662a9..61db156 100644 --- a/src/lib/xilib.sh +++ b/src/lib/xilib.sh @@ -42,5 +42,3 @@ basename () { echo ${name#$suf} } - -basename -- cgit v1.2.1 From 797b98a68976b4bb183292eacfa8a2636b82c00e Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 2 Oct 2022 15:28:12 +0000 Subject: Added hbar as sh --- src/util/hbar.sh | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/hbar.sh | 10 +++--- 2 files changed, 100 insertions(+), 5 deletions(-) create mode 100755 src/util/hbar.sh diff --git a/src/util/hbar.sh b/src/util/hbar.sh new file mode 100755 index 0000000..25343bd --- /dev/null +++ b/src/util/hbar.sh @@ -0,0 +1,95 @@ +#!/bin/sh +. /usr/lib/colors.sh + +move_up () { + [ ! "$1" = "-1" ] && + printf "\033[%dA" "$1" "0" +} + +move_down () { + [ ! "$1" = "-1" ] && + printf "\033[%dA" "$1" +} + +count_string () { + local c t + $human && { + c=$(format_bytes $completed) + t=$(format_bytes $total) + } || { + c=$1 + t=$2 + } + printf "[%s%s/%s%s]" $c $unit $t $unit +} + +hbar () { + local width terminate human text color reset unit line count + width=$(tput cols) + color=$BG_BLUE + reset=$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 ] && { + printf "$RESET\n" + exit 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" + + printf " " + i=$((i+1)) + done + + move_down $line + + $terminate && printf "$RESET\n" + + exit 0 +} + +hbar $@ diff --git a/test/hbar.sh b/test/hbar.sh index 71713ef..4a124f2 100755 --- a/test/hbar.sh +++ b/test/hbar.sh @@ -1,13 +1,13 @@ #!/bin/sh -HBAR=./bin/hbar +HBAR=./dist/hbar UNIT="mb" MAX=100 TEXT="✓ Привет World Привет World Привет World Привет World Привет World Привет World " for x in $(seq $MAX); do ${HBAR} -T "${TEXT}" -u ${UNIT} $x $MAX - sleep 0.01 + #sleep 0.01 done TEXT="Hello there" @@ -15,7 +15,7 @@ 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 + #sleep 0.01 done ${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX @@ -23,7 +23,7 @@ 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 + #sleep 0.01 done ${HBAR} -l 1 -T "${TEXT}" $x $MAX ${HBAR} -l 0 -t -T "${TEXT}" $((MAX-x)) $MAX @@ -32,6 +32,6 @@ MAX=20000000 for x in $(seq 0 991 $MAX); do ${HBAR} -h -T "${TEXT}" $x $MAX - sleep 0.01 + #sleep 0.01 done ${HBAR} -ht -T "${TEXT}" $x $MAX -- cgit v1.2.1 From 3272a63cf1dcc23252ffebb792466b797ad3a146 Mon Sep 17 00:00:00 2001 From: davidovski Date: Thu, 6 Oct 2022 08:48:04 +0100 Subject: Fixed hbar printing issue --- src/util/hbar.sh | 18 ++++++++++++------ test/hbar.sh | 17 +++++++++++++++-- 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 -- cgit v1.2.1 From 9777607077f003960192f242237eece2ab6b4d7c Mon Sep 17 00:00:00 2001 From: davidovski Date: Mon, 16 Jan 2023 22:31:22 +0000 Subject: Fix typo in xitui --- src/lib/xitui.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/xitui.sh b/src/lib/xitui.sh index f47adb3..33d5e87 100644 --- a/src/lib/xitui.sh +++ b/src/lib/xitui.sh @@ -359,7 +359,6 @@ t_input () { t_msg "$@ >" > $(tty) - stty echo t_yes_cur read var t_set_tty -- cgit v1.2.1 From 7c764a03a491edf85c2aed8f5108f64b9f5a8d87 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sat, 21 Jan 2023 12:59:09 +0000 Subject: Update build to include hbar.sh --- build.shmk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build.shmk b/build.shmk index 1ba3a21..0a74b6c 100755 --- a/build.shmk +++ b/build.shmk @@ -6,16 +6,17 @@ LIBS="src/lib/*.sh" PROGS=" src/util/shmk.sh +src/util/hbar.sh src/util/shtests.sh src/util/parseconf.sh src/tools/xichroot.sh src/tools/default-jvm.sh " -prog_hbar () { - cp src/lib/colors.h ${DIST} - ${CC} -I${DIST} -o ${DIST}/hbar src/util/hbar.c -} +#prog_hbar () { + #cp src/lib/colors.h ${DIST} + #${CC} -I${DIST} -o ${DIST}/hbar src/util/hbar.c +#} check_shtests () { ${DIST}/shtests test/parseconf.sh -- cgit v1.2.1 From 53e854ffc351785c029ed610902b979572beeb80 Mon Sep 17 00:00:00 2001 From: davidovski Date: Thu, 2 Feb 2023 10:42:59 +0000 Subject: Fix hbar with no arguments --- src/util/hbar.sh | 29 ++++++++++++++++++++--------- test/hbar.sh | 14 ++++++++------ 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 -- cgit v1.2.1 From 2f2cba16754b0561267d3ac9dc1b149537e05429 Mon Sep 17 00:00:00 2001 From: davidovski Date: Thu, 2 Feb 2023 10:52:16 +0000 Subject: Use shmk include instead of shell import --- src/util/hbar.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/hbar.sh b/src/util/hbar.sh index 502bdc1..e0af560 100755 --- a/src/util/hbar.sh +++ b/src/util/hbar.sh @@ -1,6 +1,6 @@ #!/bin/sh -. /usr/lib/colors.sh -. /usr/lib/xilib.sh +#include colors +#include xilib move_up () { [ ! "$1" = "0" ] && -- cgit v1.2.1