MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

60 lines
1.3 KiB

# CONSTANTS
# MARGIN=0
PADDING=0
ANSI_RESET='\e[0m'
declare -A FG_COLORS
FG_COLORS["RED"]='\e[31m'
FG_COLORS["GREEN"]='\e[32m'
FG_COLORS["YELLOW"]='\e[93m'
FG_COLORS["BLUE"]='\e[34m'
FG_COLORS["CYAN"]='\e[36m'
FG_COLORS["MAGENTA"]='\e[95m'
FG_COLORS["GRAY"]='\e[90m'
# FUNCTIONS
function ansi_length {
local clean_text
clean_text=$(echo "$1" | sed 's/\x1B\[[0-9;]*m//g')
echo "${#clean_text}"
}
function style_padding {
local padding_left=${PADDING_LEFT:-$PADDING}
local padding_right=${PADDING_RIGHT:-$PADDING}
for _ in $(seq 1 "${padding_left}"); do builtin echo -n ' '; done
builtin echo -n "$1"
for _ in $(seq 1 "${padding_right}"); do builtin echo -n ' '; done
}
function _style_fg {
[[ -n $1 ]] && echo "${FG_COLORS[$1]}" || true
}
function style_ansi {
local fg
fg=$(_style_fg "${FG:-}")
# local bg=${BG:-}
[[ -n $fg ]] && builtin echo -en "$fg"
builtin echo -en "$1"
[[ -n $fg ]] && builtin echo -en "$ANSI_RESET"
}
function style_block {
local content length
content=$(style_padding "$1")
length=$(ansi_length "$content")
length=$((length + 2))
builtin echo -n "╔"
for _ in $(seq 1 "${length}"); do builtin echo -n '═'; done
builtin echo "╗"
builtin echo "$content"
builtin echo -n "╚"
for _ in $(seq 1 "${length}"); do builtin echo -n '═'; done
builtin echo "╝"
}