From b6eb01bb34f7266da9d1e250bf741a8e617a40e6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 25 Aug 2024 21:17:31 +0200 Subject: [PATCH] internal --- spcd/main.sh | 276 +++++++++++++++++++++++++-------------------------- 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/spcd/main.sh b/spcd/main.sh index 9166e9a..b9288c5 100644 --- a/spcd/main.sh +++ b/spcd/main.sh @@ -31,6 +31,144 @@ [ -n "${SPCD_URL_UBUNTU}" ] || SPCD_URL_UBUNTU="https://ubuntu.mirrors.ovh.net" +# ╭──────────╮ +# │ internal │ +# ╰──────────╯ + +spcd_fill() { + spcd_fill__index=${1} + while [ "${spcd_fill__index}" -gt 0 ]; do + printf "%s" "${2}" + spcd_fill__index=$((spcd_fill__index - 1)) + done +} + +# ╭──────────┬────────╮ +# │ 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_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_banner_append \ + "${spcd_ba__filler}" "${spcd_ba__text}" "${spcd_ba__filler}" + fi +} + +spcd_banner_add_index() { + unset spcd_bai__label + unset spcd_bai__level + while true; do + spcd_bai__level=$((spcd_bai__level + 1)) + eval "spcd_bai__value=\"\${SPCD_STEP_${spcd_bai__level}_INDEX}\"" + [ -n "${spcd_bai__value}" ] || break + if [ -n "${spcd_bai__label}" ]; then + spcd_bai__label="${spcd_bai__label}.${spcd_bai__value}" + else + spcd_bai__label="${spcd_bai__value}" + fi + done + spcd_banner_add "${spcd_bai__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}" + fi +} + +spcd_banner_close() { + spcd_banner_append \ + "${SPCD_BANNER_DOWN_AND_LEFT}" \ + "${SPCD_BANNER_VERTICAL}" \ + "${SPCD_BANNER_UP_AND_LEFT}" +} + +spcd_banner_echo() { + echo "\ +${SPCD_BANNER_TOP} +${SPCD_BANNER_MIDDLE} +${SPCD_BANNER_BOTTOM}" +} + +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_STEP_${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_split() { + spcd_banner_append \ + "${SPCD_BANNER_DOWN_AND_HORIZONTAL}" \ + "${SPCD_BANNER_VERTICAL}" \ + "${SPCD_BANNER_UP_AND_HORIZONTAL}" +} + +spcd_banner_unset() { + unset \ + SPCD_BANNER_TOP \ + SPCD_BANNER_MIDDLE \ + SPCD_BANNER_BOTTOM +} + +# ╭──────────┬───────╮ +# │ internal │ error │ +# ╰──────────┴───────╯ + +SPCD_ERROR_CI=1 +SPCD_ERROR_OS=2 + +# ╭──────────┬──────╮ +# │ internal │ step │ +# ╰──────────┴──────╯ + +SPCD_STEP_LEVEL=1 + +spcd_step_wipe() { + unset \ + "SPCD_STEP_${SPCD_STEP_LEVEL}_INDEX" \ + "SPCD_STEP_${SPCD_STEP_LEVEL}_LABEL" +} + # ╭───────┬─────╮ # │ steps │ env │ # ╰───────┴─────╯ @@ -1077,144 +1215,6 @@ SPCD_VERT="${SPCD_BOX_VERTICAL}" SPCD_SPLT="${SPCD_BOX_RIGHT}${SPCD_HORIZONTAL}" SPCD_SHUT="${SPCD_BOX_UP}${SPCD_BOX_LEFT}" -# ╭──────────╮ -# │ internal │ -# ╰──────────╯ - -spcd_fill() { - spcd_fill__index=${1} - while [ "${spcd_fill__index}" -gt 0 ]; do - printf "%s" "${2}" - spcd_fill__index=$((spcd_fill__index - 1)) - done -} - -# ╭──────────┬────────╮ -# │ 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_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_banner_append \ - "${spcd_ba__filler}" "${spcd_ba__text}" "${spcd_ba__filler}" - fi -} - -spcd_banner_add_index() { - unset spcd_bai__label - unset spcd_bai__level - while true; do - spcd_bai__level=$((spcd_bai__level + 1)) - eval "spcd_bai__value=\"\${SPCD_STEP_${spcd_bai__level}_INDEX}\"" - [ -n "${spcd_bai__value}" ] || break - if [ -n "${spcd_bai__label}" ]; then - spcd_bai__label="${spcd_bai__label}.${spcd_bai__value}" - else - spcd_bai__label="${spcd_bai__value}" - fi - done - spcd_banner_add "${spcd_bai__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}" - fi -} - -spcd_banner_close() { - spcd_banner_append \ - "${SPCD_BANNER_DOWN_AND_LEFT}" \ - "${SPCD_BANNER_VERTICAL}" \ - "${SPCD_BANNER_UP_AND_LEFT}" -} - -spcd_banner_echo() { - echo "\ -${SPCD_BANNER_TOP} -${SPCD_BANNER_MIDDLE} -${SPCD_BANNER_BOTTOM}" -} - -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_STEP_${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_split() { - spcd_banner_append \ - "${SPCD_BANNER_DOWN_AND_HORIZONTAL}" \ - "${SPCD_BANNER_VERTICAL}" \ - "${SPCD_BANNER_UP_AND_HORIZONTAL}" -} - -spcd_banner_unset() { - unset \ - SPCD_BANNER_TOP \ - SPCD_BANNER_MIDDLE \ - SPCD_BANNER_BOTTOM -} - -# ╭──────────┬───────╮ -# │ internal │ error │ -# ╰──────────┴───────╯ - -SPCD_ERROR_CI=1 -SPCD_ERROR_OS=2 - -# ╭──────────┬──────╮ -# │ internal │ step │ -# ╰──────────┴──────╯ - -SPCD_STEP_LEVEL=1 - -spcd_step_wipe() { - unset \ - "SPCD_STEP_${SPCD_STEP_LEVEL}_INDEX" \ - "SPCD_STEP_${SPCD_STEP_LEVEL}_LABEL" -} - # ╭──────╮ # │ main │ # ╰──────╯