export F_BOLD="\e[1m" export F_NONE="\e[0m" export C_NONE="\e[0m" export C_RED="\e[38;5;9m" export C_BLUE="\e[38;5;12m" export C_GREEN="\e[38;5;2m" export C_ORANGE="\e[38;5;208m" export C_YELLOW="\e[38;5;220m" export C_PURPLE="\e[38;5;5m" export S_DEBUG="${C_PURPLE}\u2691 [debug]${F_NONE} " export S_CRIT="${C_RED}\u2691 [critical]${F_NONE} " export S_ERROR="${C_RED}\u2691 [error]${F_NONE} " export S_WARN="${C_ORANGE}\u2691 [warning]${F_NONE} " export S_INFO="${C_BLUE}\u2691 [info]${F_NONE} " export S_NOTICE="${C_BLUE}\u2691 [notice]${F_NONE} " export S_SUCCESS="${C_GREEN}\u2691 [success]${F_NONE} " export U_ITEM="\u21e2" export U_TICK="\u2713" export U_FAIL="\u2715" export COLS="$(( $(tput cols) - 1 ))" export EL=$(tput el) cli.cursor_pos() { local _xy echo -ne $"\E[6n" read -rsdR _xy _xy="${_xy#*[}" export CURSOR_X=${_xy/*;} export CURSOR_Y=${_xy/;*} return 0 } cli.status() { printf "%0.s\n" case "${1:-info}" in debug) printf "\e[0F${S_DEBUG}${2:-%s}" "${@:3}${EL}" ;; crit*) printf "\e[0F${S_CRIT}${2:-%s}" "${@:3}${EL}" ;; error) printf "\e[0F${S_ERROR}${2:-%s}" "${@:3}${EL}" ;; warn*) printf "\e[0F${S_WARN}${2:-%s}" "${@:3}${EL}" ;; info*) printf "\e[0F${S_INFO}${2:-%s}" "${@:3}${EL}" ;; noti*) printf "\e[0F${S_NOTICE}${2:-%s}" "${@:3}${EL}" ;; succ*) printf "\e[0F${S_SUCCESS}${2:-%s}" "${@:3}${EL}" ;; *) printf "\e[0F${S_INFO}${2:-%s}" "${@:3}${EL}" ;; esac return 0 } cli.color() { case "${1:-info}" in red) printf "${C_RED}${2:-%s}${C_NONE}" "${@:3}${EL}" ;; blue) printf "${C_BLUE}${2:-%s}${C_NONE}" "${@:3}${EL}" ;; green) printf "${C_GREEN}${2:-%s}${C_NONE}" "${@:3}${EL}" ;; orange) printf "${C_ORANGE}${2:-%s}${C_NONE}" "${@:3}${EL}" ;; yellow) printf "${C_YELLOW}${2:-%s}${C_NONE}" "${@:3}${EL}" ;; purple) printf "${C_PURPLE}${2:-%s}${C_NONE}" "${@:3}${EL}" ;; *) printf "${C_NONE}${2:-%s}${C_NONE}" "${@:3}${EL}" ;; esac return 0 } cli.bold() { printf "${F_BOLD}${1:-%s}${F_NONE}" "${@:2}${EL}" return 0 } cli.section() { __section.header() { __section.title() { printf $"${@:1:1}" \ $(echo -ne ${F_BOLD}${C_BLUE}${@:2:1}${F_NONE}) \ $(echo -ne ${C_ORANGE}${@:3}${F_NONE}) } __section.title.underline() { for i in $(seq 1 ${COLS}); do \ printf "%s" $(echo -ne "\u2581"); \ done } __section.title "${@}" __section.title.underline } __section.content() { printf "%2s\n" printf "%s" "${@}" | fold -sw ${COLS} } __section.footer() { __section.footer.line() { [ -z "${1:-}" ] && printf "%s\n" for i in $(seq 1 ${COLS}); do \ printf "%s" $(echo -ne "\u2504${F_NONE}"); \ done && \ [ -z "${1:-}" ] && printf "%2s\n" } __section.footer.line } __section.header "${@:1:3}" __section.content "${@:4}" __section.footer }