diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/colors.h | 45 | ||||
| -rw-r--r-- | src/lib/colors.list | 42 | ||||
| -rw-r--r-- | src/lib/colors.sh | 44 | ||||
| -rw-r--r-- | src/lib/generate_colors.sh | 44 | ||||
| -rw-r--r-- | src/lib/libhbar.sh | 116 |
5 files changed, 116 insertions, 175 deletions
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 "[0m" -#define BOLD "[0;1m" -#define BLACK "[0;30m" -#define RED "[0;31m" -#define GREEN "[0;32m" -#define YELLOW "[0;33m" -#define BLUE "[0;34m" -#define MAGENTA "[0;35m" -#define CYAN "[0;36m" -#define WHITE "[0;37m" -#define DEFAULT "[0;39m" -#define BG_BLACK "[40m" -#define BG_RED "[41m" -#define BG_GREEN "[42m" -#define BG_YELLOW "[43m" -#define BG_BLUE "[44m" -#define BG_MAGENTA "[45m" -#define BG_CYAN "[46m" -#define BG_WHITE "[47m" -#define BG_DEFAULT "[49m" -#define LIGHT_BLACK "[0;90m" -#define LIGHT_RED "[0;91m" -#define LIGHT_GREEN "[0;92m" -#define LIGHT_YELLOW "[0;93m" -#define LIGHT_BLUE "[0;94m" -#define LIGHT_MAGENTA "[0;95m" -#define LIGHT_CYAN "[0;96m" -#define LIGHT_WHITE "[0;97m" -#define LIGHT_DEFAULT "[0;99m" -#define BOLDBLACK "[1;30m" -#define BOLDRED "[1;31m" -#define BOLDGREEN "[1;32m" -#define BOLDYELLOW "[1;33m" -#define BOLDBLUE "[1;34m" -#define BOLDMAGENTA "[1;35m" -#define BOLDCYAN "[1;36m" -#define BOLDWHITE "[1;37m" 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 "[0m") -export BOLD=$(printf "[0;1m") -export BLACK=$(printf "[0;30m") -export RED=$(printf "[0;31m") -export GREEN=$(printf "[0;32m") -export YELLOW=$(printf "[0;33m") -export BLUE=$(printf "[0;34m") -export MAGENTA=$(printf "[0;35m") -export CYAN=$(printf "[0;36m") -export WHITE=$(printf "[0;37m") -export DEFAULT=$(printf "[0;39m") -export BG_BLACK=$(printf "[40m") -export BG_RED=$(printf "[41m") -export BG_GREEN=$(printf "[42m") -export BG_YELLOW=$(printf "[43m") -export BG_BLUE=$(printf "[44m") -export BG_MAGENTA=$(printf "[45m") -export BG_CYAN=$(printf "[46m") -export BG_WHITE=$(printf "[47m") -export BG_DEFAULT=$(printf "[49m") -export LIGHT_BLACK=$(printf "[0;90m") -export LIGHT_RED=$(printf "[0;91m") -export LIGHT_GREEN=$(printf "[0;92m") -export LIGHT_YELLOW=$(printf "[0;93m") -export LIGHT_BLUE=$(printf "[0;94m") -export LIGHT_MAGENTA=$(printf "[0;95m") -export LIGHT_CYAN=$(printf "[0;96m") -export LIGHT_WHITE=$(printf "[0;97m") -export LIGHT_DEFAULT=$(printf "[0;99m") -export BOLDBLACK=$(printf "[1;30m") -export BOLDRED=$(printf "[1;31m") -export BOLDGREEN=$(printf "[1;32m") -export BOLDYELLOW=$(printf "[1;33m") -export BOLDBLUE=$(printf "[1;34m") -export BOLDMAGENTA=$(printf "[1;35m") -export BOLDCYAN=$(printf "[1;36m") -export BOLDWHITE=$(printf "[1;37m") 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" +} + |
