diff options
| author | davidovski <david@davidovski.xyz> | 2026-10-01 10:34:33 +0100 |
|---|---|---|
| committer | davidovski <david@davidovski.xyz> | 2026-10-01 10:34:33 +0100 |
| commit | eca55e60c29440c4e2e007b54ea1a1983e965954 (patch) | |
| tree | a98173c09f69864cc25395bfdab67d682434854b | |
| parent | f20bd9d6369c2e1246dcdd4af26b085da99c18e0 (diff) | |
| -rwxr-xr-x | Makefile | 15 | ||||
| -rwxr-xr-x | build.shmk | 27 | ||||
| -rwxr-xr-x | shmk.shmk | 9 | ||||
| -rw-r--r-- | src/lib/colors.h | 45 | ||||
| -rw-r--r-- | src/lib/colors.sh | 44 | ||||
| -rw-r--r-- | src/lib/libhbar.sh | 116 | ||||
| -rw-r--r-- | src/tools/colors.list (renamed from src/lib/colors.list) | 0 | ||||
| -rw-r--r-- | src/tools/generate_colors.sh (renamed from src/lib/generate_colors.sh) | 1 | ||||
| -rwxr-xr-x | src/util/hbar.sh | 104 | ||||
| -rw-r--r-- | src/util/parseconf.sh | 42 | ||||
| -rw-r--r-- | src/util/shmk/shmk.README (renamed from src/util/shmk.README) | 12 | ||||
| -rwxr-xr-x | src/util/shmk/shmk.sh (renamed from src/util/shmk.sh) | 52 | ||||
| -rwxr-xr-x | test/hbar.sh | 19 |
13 files changed, 229 insertions, 257 deletions
@@ -4,23 +4,22 @@ PREFIX=/usr export PATH := .:$(PATH) -shmk0: +shmk0: clean @echo shmk stage0 - @install -m755 src/util/shmk.sh shmk + @install -m755 src/util/shmk/shmk.sh shmk -bootstrap: shmk0 +shmk1: shmk0 @echo shmk stage1 @./shmk.shmk build @install -m755 dist/shmk shmk -build: bootstrap +build: shmk1 @echo all xiutils @./build.shmk build -clean: shmk0 - @rm -r dist - @rm -r shmk - @./build.shmk clean +clean: + @rm -rf dist + @rm -f shmk check: build @./build.shmk check @@ -4,21 +4,26 @@ CC=gcc -LIBS="src/lib/*.sh" +LIBS=" + src/lib/xilib.sh + src/lib/libhbar.sh + src/lib/xitui.sh + src/lib/glyphs.sh + src/lib/glyphs.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 + src/util/shmk/shmk.sh + src/util/shtests.sh + src/util/parseconf.sh + src/tools/xichroot.sh + src/tools/default-jvm.sh + src/util/hbar.sh " -#prog_hbar () { - #cp src/lib/colors.h ${DIST} - #${CC} -I${DIST} -o ${DIST}/hbar src/util/hbar.c -#} +lib_colors () { + sh src/tools/generate_colors.sh "$DIST" "src/tools/colors.list" +} check_shtests () { ${DIST}/shtests test/parseconf.sh @@ -3,9 +3,14 @@ # shmk file to build shmk itself LIBS=" -src/lib/colors.sh + src/lib/libhbar.sh " PROGS=" -src/util/shmk.sh + src/util/shmk/shmk.sh " + + +lib_colors () { + sh src/tools/generate_colors.sh "$DIST" "src/tools/colors.list" +} 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.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/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" +} + diff --git a/src/lib/colors.list b/src/tools/colors.list index 0829a63..0829a63 100644 --- a/src/lib/colors.list +++ b/src/tools/colors.list diff --git a/src/lib/generate_colors.sh b/src/tools/generate_colors.sh index 6e01d58..4d1e08f 100644 --- a/src/lib/generate_colors.sh +++ b/src/tools/generate_colors.sh @@ -1,5 +1,6 @@ #!/bin/bash DIST=$1 +mkdir -p ${DIST} headerfile=${DIST}/colors.h shlib=${DIST}/colors.sh diff --git a/src/util/hbar.sh b/src/util/hbar.sh index 9518e66..230ff5d 100755 --- a/src/util/hbar.sh +++ b/src/util/hbar.sh @@ -1,108 +1,6 @@ #!/bin/mksh -U -#include colors -#include xilib -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 - 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 ] && { - 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)) - - i=0 - while [ "$i" -lt "$width" ]; do - [ "$i" = "$reset_at" ] && printf "$reset" - - [ "${#text}" -gt 0 ] && { - printf "%s" "${text%%${text#?}}" - text="${text#?}" - } || { - [ "$((width-${#count}))" = "$i" ] && { - printf "%s" "${count%%${count#?}}" - count="${count#?}" - } || { - printf " " - } - } - i=$((i+1)) - done - - move_down $line - - printf "$RESET" - $terminate && printf "\n" - - exit 0 -} +#include libhbar [ "$#" -eq "0" ] && { printf "$RESET\n" diff --git a/src/util/parseconf.sh b/src/util/parseconf.sh index d215a99..17cb0ce 100644 --- a/src/util/parseconf.sh +++ b/src/util/parseconf.sh @@ -1,37 +1,37 @@ #!/bin/sh usage () { - printf "Usage $0 " - echo << "EOF" +printf "Usage $0 " +echo << "EOF" OPTIONS... [FILTER] Print the parsed config file filtering by the keys Arguments: - -f file read configuration from a file, uses /dev/sdtin otherwise - -v only print values - -c n print the last [n] +-f file read configuration from a file, uses /dev/sdtin otherwise +-v only print values +-c n print the last [n] EOF } # parse a single config file line # parse_line() { - [ "$#" = 0 ] && return - - local line="$@" - local key=$1 - - shift - local value="$@" - value=${value%#*} - - case $key in - "include") - cat $value | parse - return - ;; - "]") - IFS=. +[ "$#" = 0 ] && return + +local line="$@" +local key=$1 + +shift +local value="$@" +value=${value%#*} + +case $key in + "include") + cat $value | parse + return + ;; + "]") + IFS=. set -- $list list="${*%${!#}}" IFS=" " diff --git a/src/util/shmk.README b/src/util/shmk/shmk.README index a359fbc..43671ac 100644 --- a/src/util/shmk.README +++ b/src/util/shmk/shmk.README @@ -116,6 +116,14 @@ This feature is intended to be used with the `shtests` tool. ## Syntax and formatting -shmk is intended to be as portable as possible, following exclusively POSIX shell syntax. This means that unlike in bash or csh, there is no formal structure for lists, instead whitespace separated strings are used. New lines or spaces both work, however for the sake of simplicity, newlines are prefered. The "standard" shmk syntax for a list is as follows -` +### shell features + +shmk is intended to be as portable as possible, following exclusively POSIX shell syntax. This means that unlike in bash or csh, there is no formal structure for lists, instead whitespace separated strings are used. New lines or spaces both work, however for the sake of simplicity, newlines are prefered. + +### env vars + +shmk exposes a few different environment variables in the build environment (ie to be used in custom build stages): + +- `${DIST}` - temporary "out" directory where libraries and binaries are placed. +- `${PREFIX}` - where things will be installed diff --git a/src/util/shmk.sh b/src/util/shmk/shmk.sh index b4c040d..be5f00b 100755 --- a/src/util/shmk.sh +++ b/src/util/shmk/shmk.sh @@ -1,8 +1,9 @@ #!/bin/sh -# +# # A tool to build a single executable from a collection of shell scripts #include colors +#include libhbar PREFIX=${PREFIX:-/usr} @@ -18,13 +19,15 @@ EOF # _find_file filename # _find_file () { - for p in $search_path; do - for f in $p/$1.sh $p/$1; do + for p in $search_path; do + for f in $p/$1.sh $p/$1; do $verbose \ && printf "${LIGHT_BLACK}checking: $f\n" 1>&2 [ -f "$f" ] && { - echo "$f" + $verbose \ + && printf "${LIGHT_BLACK}found: $f for $1\n" 1>&2 + echo "$f" return 0 } done @@ -50,7 +53,10 @@ _parse_lines () { # if we have already included this file, do not parse it case "$included" in - *"$file"*) ;; + *"$file"*) + $verbose \ + && printf "${LIGHT_BLACK}already included $file, won't include twice\n" 1>&2 + ;; *) cat $file | _parse_lines included="$included $file" @@ -103,15 +109,19 @@ interpret_shmk () { . $1 local cmdlist="" + ## TODO override if already set DIST="./dist" - PROGS="$PROGS $(sed -rn "s/^prog_(.*)\s*\(\)\s*\{/\1/p" $1)" - LIBS="$LIBS $(sed -rn "s/^lib_(.*)\s*\(\)\s*\{/\1/p" $1)" - CHECKS="$CHECKS $(sed -rn "s/^check_(.*)\s*\(\)\s*\{/\1/p" $1)" + BUILDS="$(sed -rn "s/^build_(.*)\s*\(\)\s*\{/\1/p" $1) $BUILDS" + PROGS="$(sed -rn "s/^prog_(.*)\s*\(\)\s*\{/\1/p" $1) $PROGS " + LIBS="$(sed -rn "s/^lib_(.*)\s*\(\)\s*\{/\1/p" $1) $LIBS" + CHECKS="$(sed -rn "s/^check_(.*)\s*\(\)\s*\{/\1/p" $1) $CHECKS" shift - [ -z "$1" ] && set -- clean build check install + [ -z "$1" ] && set -- clean build check while [ ! -z "$1" ]; do case "$1" in + # install programs and libraries to system + # install) for prog in $PROGS; do prog=$(basename $prog) @@ -126,6 +136,9 @@ interpret_shmk () { install -Dm755 $DIST/$lib ${DESTDIR}/${PREFIX}/lib/$lib.sh #Install library $lib" done ;; + + # install programs and libraries to system + # uninstall) for prog in $PROGS; do prog=$(basename $prog) @@ -140,16 +153,19 @@ interpret_shmk () { rm $DIST/$lib ${DESTDIR}/${PREFIX}/lib/$lib.sh #Uninstall library $lib" done ;; + clean) [ -d "$DIST" ] && cmdlist="$cmdlist rm -r $DIST #Clean" ;; + check) for check in $CHECKS; do command -v check_$check > /dev/null 2>&1 && cmdlist="$cmdlist check_$check #Check $check" done ;; + *) # build all programs search_path="$DIST $search_path" @@ -185,7 +201,15 @@ interpret_shmk () { i=-1 echo "$cmdlist" | while read -r cmd; do i=$((i+1)) - printf "${LIGHT_BLACK}[${LIGHT_BLUE}%s${LIGHT_BLACK}/${LIGHT_BLUE}%s${LIGHT_BLACK}] ${LIGHT_WHITE}%s${RESET}%s" "$i" "$len" "${cmd#*#}" "$($verbose && printf "\n" || printf "\r")" + outstring="$(printf "${LIGHT_BLACK}[${LIGHT_BLUE}%s${LIGHT_BLACK}/${LIGHT_BLUE}%s${LIGHT_BLACK}] ${LIGHT_WHITE}%s" \ + "$i" "$len" "${cmd#*#}")" + + printf "\r%s\r" "${outstring}" #"$($verbose && printf "\n\n" || printf "\n")" + if ! $verbose && command -v hbar > /dev/null 2>&1; then + printf "\n" + hbar -l 1 -r "${RESET}" -c "${BG_BLUE}" -n "$i" "$len" + fi + ${cmd%#*} 2>&1 > $out || { printf "\n${RED}Error $?\n" exit 1 @@ -213,7 +237,7 @@ clean=false } while getopts ":e:I:o:chv" opt; do - case "${opt}" in + case "${opt}" in e) entry_function="$OPTARG" ;; @@ -224,8 +248,10 @@ while getopts ":e:I:o:chv" opt; do clean=true ;; I) - search_path="$OPTARG - $search_path" + search_path=" + $OPTARG + $search_path + " ;; v) verbose=true diff --git a/test/hbar.sh b/test/hbar.sh index c01ee25..31b3a83 100755 --- a/test/hbar.sh +++ b/test/hbar.sh @@ -4,12 +4,6 @@ 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 -done - sleep 1 clear echo Doing hello there bar @@ -18,8 +12,7 @@ sleep 1 TEXT="Hello there" for x in $(seq $MAX); do - ${HBAR} -T "${TEXT}" -u ${UNIT} $x $MAX - #sleep 0.01 + time ${HBAR} -l 2 -T "${TEXT}" -u ${UNIT} $x $MAX done ${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX @@ -50,3 +43,13 @@ for x in $(seq 0 991 $MAX); do ${HBAR} -h -T "${TEXT}" $((x*1000000)) $((MAX*1000000)) done ${HBAR} -ht -T "${TEXT}" $x $MAX + +sleep 1 +clear +echo testing unicode +sleep 1 +TEXT="✓ Привет World Привет World Привет World Привет World Привет World Привет World " +for x in $(seq $MAX); do + ${HBAR} -T "${TEXT}" -u ${UNIT} $x $MAX + #sleep 0.01 +done |
