From eca55e60c29440c4e2e007b54ea1a1983e965954 Mon Sep 17 00:00:00 2001 From: davidovski Date: Thu, 1 Oct 2026 10:34:33 +0100 Subject: Add libhbar to shmk --- src/lib/colors.h | 45 ------------------ src/lib/colors.list | 42 ---------------- src/lib/colors.sh | 44 ----------------- src/lib/generate_colors.sh | 44 ----------------- src/lib/libhbar.sh | 116 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 175 deletions(-) delete mode 100644 src/lib/colors.h delete mode 100644 src/lib/colors.list delete mode 100644 src/lib/colors.sh delete mode 100644 src/lib/generate_colors.sh create mode 100644 src/lib/libhbar.sh (limited to 'src/lib') diff --git a/src/lib/colors.h b/src/lib/colors.h deleted file mode 100644 index e7bc26d..0000000 --- a/src/lib/colors.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * colors.h - * - * list of ansi color codes - * provided by xiutils - * - */ - -#define RESET "" -#define BOLD "" -#define BLACK "" -#define RED "" -#define GREEN "" -#define YELLOW "" -#define BLUE "" -#define MAGENTA "" -#define CYAN "" -#define WHITE "" -#define DEFAULT "" -#define BG_BLACK "" -#define BG_RED "" -#define BG_GREEN "" -#define BG_YELLOW "" -#define BG_BLUE "" -#define BG_MAGENTA "" -#define BG_CYAN "" -#define BG_WHITE "" -#define BG_DEFAULT "" -#define LIGHT_BLACK "" -#define LIGHT_RED "" -#define LIGHT_GREEN "" -#define LIGHT_YELLOW "" -#define LIGHT_BLUE "" -#define LIGHT_MAGENTA "" -#define LIGHT_CYAN "" -#define LIGHT_WHITE "" -#define LIGHT_DEFAULT "" -#define BOLDBLACK "" -#define BOLDRED "" -#define BOLDGREEN "" -#define BOLDYELLOW "" -#define BOLDBLUE "" -#define BOLDMAGENTA "" -#define BOLDCYAN "" -#define BOLDWHITE "" diff --git a/src/lib/colors.list b/src/lib/colors.list deleted file mode 100644 index 0829a63..0000000 --- a/src/lib/colors.list +++ /dev/null @@ -1,42 +0,0 @@ -RESET "\033[0m" - -BOLD "\033[0;1m" - -BLACK "\033[0;30m" -RED "\033[0;31m" -GREEN "\033[0;32m" -YELLOW "\033[0;33m" -BLUE "\033[0;34m" -MAGENTA "\033[0;35m" -CYAN "\033[0;36m" -WHITE "\033[0;37m" -DEFAULT "\033[0;39m" - -BG_BLACK "\033[40m" -BG_RED "\033[41m" -BG_GREEN "\033[42m" -BG_YELLOW "\033[43m" -BG_BLUE "\033[44m" -BG_MAGENTA "\033[45m" -BG_CYAN "\033[46m" -BG_WHITE "\033[47m" -BG_DEFAULT "\033[49m" - -LIGHT_BLACK "\033[0;90m" -LIGHT_RED "\033[0;91m" -LIGHT_GREEN "\033[0;92m" -LIGHT_YELLOW "\033[0;93m" -LIGHT_BLUE "\033[0;94m" -LIGHT_MAGENTA "\033[0;95m" -LIGHT_CYAN "\033[0;96m" -LIGHT_WHITE "\033[0;97m" -LIGHT_DEFAULT "\033[0;99m" - -BOLDBLACK "\033[1;30m" -BOLDRED "\033[1;31m" -BOLDGREEN "\033[1;32m" -BOLDYELLOW "\033[1;33m" -BOLDBLUE "\033[1;34m" -BOLDMAGENTA "\033[1;35m" -BOLDCYAN "\033[1;36m" -BOLDWHITE "\033[1;37m" diff --git a/src/lib/colors.sh b/src/lib/colors.sh deleted file mode 100644 index 8e5de11..0000000 --- a/src/lib/colors.sh +++ /dev/null @@ -1,44 +0,0 @@ -# -# colors.h -# -# list of ansi color codes -# provided by xiutils -# - -export RESET=$(printf "") -export BOLD=$(printf "") -export BLACK=$(printf "") -export RED=$(printf "") -export GREEN=$(printf "") -export YELLOW=$(printf "") -export BLUE=$(printf "") -export MAGENTA=$(printf "") -export CYAN=$(printf "") -export WHITE=$(printf "") -export DEFAULT=$(printf "") -export BG_BLACK=$(printf "") -export BG_RED=$(printf "") -export BG_GREEN=$(printf "") -export BG_YELLOW=$(printf "") -export BG_BLUE=$(printf "") -export BG_MAGENTA=$(printf "") -export BG_CYAN=$(printf "") -export BG_WHITE=$(printf "") -export BG_DEFAULT=$(printf "") -export LIGHT_BLACK=$(printf "") -export LIGHT_RED=$(printf "") -export LIGHT_GREEN=$(printf "") -export LIGHT_YELLOW=$(printf "") -export LIGHT_BLUE=$(printf "") -export LIGHT_MAGENTA=$(printf "") -export LIGHT_CYAN=$(printf "") -export LIGHT_WHITE=$(printf "") -export LIGHT_DEFAULT=$(printf "") -export BOLDBLACK=$(printf "") -export BOLDRED=$(printf "") -export BOLDGREEN=$(printf "") -export BOLDYELLOW=$(printf "") -export BOLDBLUE=$(printf "") -export BOLDMAGENTA=$(printf "") -export BOLDCYAN=$(printf "") -export BOLDWHITE=$(printf "") diff --git a/src/lib/generate_colors.sh b/src/lib/generate_colors.sh deleted file mode 100644 index 6e01d58..0000000 --- a/src/lib/generate_colors.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -DIST=$1 - -headerfile=${DIST}/colors.h -shlib=${DIST}/colors.sh - -cat > $shlib << "EOF" -# -# colors.h -# -# list of ansi color codes -# provided by xiutils -# - -EOF - -cat > $headerfile << "EOF" -/* - * colors.h - * - * list of ansi color codes - * provided by xiutils - * - */ - -EOF - -append_header() { - echo "#define $1 $2" >> $headerfile -} - -append_sh() { - printf 'export %s=$(printf %s)\n' $1 $2 >> $shlib -} - -while IFS= read -r line; do - echo "$line" | grep -q "." || continue - name=$(echo $line | awk '{ print $1 }') - code=$(echo $line | awk '{ print $2 }') - - append_header $name $code - append_sh $name $code - -done < "$2" diff --git a/src/lib/libhbar.sh b/src/lib/libhbar.sh new file mode 100644 index 0000000..4489f09 --- /dev/null +++ b/src/lib/libhbar.sh @@ -0,0 +1,116 @@ +#!/bin/mksh -U +#include colors +#include xilib + +ADVANCE=" " + +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 + # dont write any real characters ya + notext=false + line=0 + + while getopts "T:c:r:u:l:hnt" 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" + ;; + n) + notext=true + 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)) + + _x=0 + while [ "$_x" -lt "$width" ]; do + + if $notext; then + [ "$_x" -gt "$reset_at" ] && printf "$reset" || printf "$color" + printf "%s" "$ADVANCE" + else + [ "$_x" = "$reset_at" ] && printf "$reset" + if [ "${#text}" -gt 0 ]; then + printf "%s" "${text%%${text#?}}" + text="${text#?}" + else + if [ "$((width-${#count}))" = "$_x" ]; then + printf "%s" "${count%%${count#?}}" + + count="${count#?}" + else + printf "$ADVANCE" + fi + fi + fi + _x=$((_x+1)) + done + + move_down $line + + printf "$RESET" + $terminate && printf "\n" +} + -- cgit v1.2.3