diff --git a/readme.md b/readme.md index c8ab4a9..8e85647 100644 --- a/readme.md +++ b/readme.md @@ -213,15 +213,13 @@ Handle project workflows in a unified way: ### Shell -* banner - * constants for characters - * dynamic substeps +* banner with constants for characters * comment * review repositories handling for systems * opensuse * codecs repository * disable & enable https -* test +* write unit tests ### Shell → Python @@ -249,7 +247,6 @@ Handle project workflows in a unified way: * .py * .sh * maximum line length -* comment * detect ssh private key type * fit banner to text * implement substeps @@ -258,7 +255,7 @@ Handle project workflows in a unified way: * actions * includes * try git repo url variable first for shunit -* test +* write unit tests ### Later diff --git a/spcd/main.sh b/spcd/main.sh index 0835f1e..5b1b34c 100644 --- a/spcd/main.sh +++ b/spcd/main.sh @@ -866,30 +866,6 @@ ${SPCD_PYTHON_ALIAS} / ${spcd_stp__name}" "${SPCD_PYTHON_ALIAS}" -m "${spcd_stp__name}" } -# ╭───────────┬──────╮ -# │ functions │ step │ -# ╰───────────┴──────╯ - -spcd_step() { - if [ -n "${1}" ]; then - spcd_step__prefix="SPCD_STEP_${SPCD_STEP_LEVEL}" - spcd_step__index="${spcd_step__prefix}_INDEX" - eval "${spcd_step__index}=\$((${spcd_step__index} + 1))" - eval "${spcd_step__prefix}_LABEL=\"${1}\"" - spcd_banner_render - fi -} - -spcd_step_in() { - SPCD_STEP_LEVEL=$((SPCD_STEP_LEVEL + 1)) - spcd_step_wipe -} - -spcd_step_out() { - spcd_step_wipe - SPCD_STEP_LEVEL=$((SPCD_STEP_LEVEL - 1)) -} - # ╭───────────╮ # │ functions │ # ╰───────────╯ @@ -1040,6 +1016,19 @@ spcd_split() { echo "${SPCD_SPLT}" } +spcd_step() { + SPCD_STEP=$((SPCD_STEP + 1)) + SPCD_STEP_TEXT="${*}" + unset SPCD_SUBSTEP SPCD_SUBSTEP_TEXT + spcd_banner +} + +spcd_substep() { + SPCD_SUBSTEP=$((SPCD_SUBSTEP + 1)) + SPCD_SUBSTEP_TEXT="${*}" + spcd_banner +} + spcd_write() { spcd_write__file="${1}" spcd_write__text="${2}" @@ -1108,123 +1097,74 @@ spcd_fill() { # │ internal │ banner │ # ╰──────────┴────────╯ -SPCD_BANNER_DOWN_AND_HORIZONTAL="┬" -SPCD_BANNER_DOWN_AND_LEFT="╮" -SPCD_BANNER_DOWN_AND_RIGHT="╭" -SPCD_BANNER_HORIZONTAL="─" -SPCD_BANNER_UP_AND_HORIZONTAL="┴" -SPCD_BANNER_UP_AND_LEFT="╯" -SPCD_BANNER_UP_AND_RIGHT="╰" -SPCD_BANNER_VERTICAL="│" +spcd_banner() { + spcd_banner_unset + spcd_banner_open + # + spcd_banner__index="${SPCD_STEP}" + [ -n "${SPCD_SUBSTEP}" ] && + spcd_banner__index="${spcd_banner__index}.${SPCD_SUBSTEP}" + spcd_banner_add "${spcd_banner__index}" + # + spcd_banner_split + spcd_banner_add "S" + # + for spcd_banner__item in "${SPCD_STEP_TEXT}" "${SPCD_SUBSTEP_TEXT}"; do + if [ -n "${spcd_banner__item}" ]; then + spcd_banner_split + spcd_banner_add "${spcd_banner__item}" + fi + done + # + spcd_banner_close + # + spcd_banner_echo + spcd_banner_unset +} spcd_banner_add() { if [ -n "${1}" ]; then spcd_ba__text=" ${1} " spcd_ba__length=${#spcd_ba__text} - spcd_ba__filler="$( - spcd_fill "${spcd_ba__length}" "${SPCD_BANNER_HORIZONTAL}" - )" - if [ -n "${SPCD_BANNER_MIDDLE}" ]; then - spcd_banner_split - else - spcd_banner_open - fi + spcd_ba__filler="$(spcd_fill "${spcd_ba__length}" ─)" spcd_banner_append \ "${spcd_ba__filler}" "${spcd_ba__text}" "${spcd_ba__filler}" fi } -spcd_banner_add_index() { - unset spcd_bi__label - unset spcd_bi__level - while true; do - spcd_bi__level=$((spcd_bi__level + 1)) - eval "spcd_bi__value=\"\${SPCD_BANNER_${spcd_bi__level}_INDEX}\"" - [ -n "${spcd_bi__value}" ] || break - if [ -n "${spcd_bi__label}" ]; then - spcd_bi__label="${spcd_bi__label}.${spcd_bi__value}" - else - spcd_bi__label="${spcd_bi__value}" - fi - done - spcd_banner_add "${spcd_bi__label}" -} - spcd_banner_append() { if [ -n "${3}" ]; then - SPCD_BANNER_TOP="${SPCD_BANNER_TOP}${1}" - SPCD_BANNER_MIDDLE="${SPCD_BANNER_MIDDLE}${2}" - SPCD_BANNER_BOTTOM="${SPCD_BANNER_BOTTOM}${3}" + SPCD_BANNER_1="${SPCD_BANNER_1}${1}" + SPCD_BANNER_2="${SPCD_BANNER_2}${2}" + SPCD_BANNER_3="${SPCD_BANNER_3}${3}" fi } spcd_banner_close() { - spcd_banner_append \ - "${SPCD_BANNER_DOWN_AND_LEFT}" \ - "${SPCD_BANNER_VERTICAL}" \ - "${SPCD_BANNER_UP_AND_LEFT}" + spcd_banner_append "╮" "${SPCD_VERT}" "╯" } spcd_banner_echo() { echo "\ -${SPCD_BANNER_TOP} -${SPCD_BANNER_MIDDLE} -${SPCD_BANNER_BOTTOM}" +${SPCD_BANNER_1} +${SPCD_BANNER_2} +${SPCD_BANNER_3}" } spcd_banner_open() { - spcd_banner_append \ - "${SPCD_BANNER_DOWN_AND_RIGHT}" \ - "${SPCD_BANNER_VERTICAL}" \ - "${SPCD_BANNER_UP_AND_RIGHT}" -} - -spcd_banner_render() { - spcd_banner_unset - spcd_banner_add_index - spcd_banner_add "S" - # - unset spcd_br__level - while true; do - spcd_br__level=$((spcd_br__level + 1)) - eval "spcd_br__value=\"\${SPCD_BANNER_${spcd_br__level}_LABEL}\"" - [ -n "${spcd_br__value}" ] || break - spcd_banner_add "${spcd_br__value}" - done - # - spcd_banner_close - spcd_banner_echo - spcd_banner_unset + spcd_banner_append "${SPCD_BOX_DOWN}" "${SPCD_VERT}" "${SPCD_BOX_UP}" } spcd_banner_split() { - spcd_banner_append \ - "${SPCD_BANNER_DOWN_AND_HORIZONTAL}" \ - "${SPCD_BANNER_VERTICAL}" \ - "${SPCD_BANNER_UP_AND_HORIZONTAL}" + spcd_banner_append "┬" "${SPCD_VERT}" "┴" } spcd_banner_unset() { - unset \ - SPCD_BANNER_TOP \ - SPCD_BANNER_MIDDLE \ - SPCD_BANNER_BOTTOM + unset SPCD_BANNER_1 SPCD_BANNER_2 SPCD_BANNER_3 } -# ╭──────────┬──────╮ -# │ internal │ step │ -# ╰──────────┴──────╯ - -SPCD_STEP=1 - -spcd_step_wipe() { - unset \ - "SPCD_STEP_${SPCD_STEP_LEVEL}_INDEX" \ - "SPCD_STEP_${SPCD_STEP_LEVEL}_LABEL" -} - -# ╭──────────╮ -# │ internal │ -# ╰──────────╯ +# ╭──────────┬─────╮ +# │ internal │ run │ +# ╰──────────┴─────╯ spcd_main