This commit is contained in:
Marc Beninca 2024-08-25 21:17:31 +02:00
parent 1d99abf92a
commit b6eb01bb34
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -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 │
# ╰──────╯