dotfiles/script_helpers/printing.sh

45 lines
751 B
Bash
Raw Normal View History

2020-07-25 23:39:09 +00:00
#!/usr/bin/env bash
2019-07-03 21:08:59 +00:00
if which tput >/dev/null 2>&1; then
2020-07-26 17:58:29 +00:00
ncolors=$(tput colors)
2019-07-03 21:08:59 +00:00
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
2020-07-26 17:58:29 +00:00
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
2020-08-26 00:50:04 +00:00
DIM="\e[2m"
2020-07-26 17:58:29 +00:00
NORMAL="$(tput sgr0)"
2019-07-03 21:08:59 +00:00
else
2020-07-26 17:58:29 +00:00
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
2019-07-03 21:08:59 +00:00
fi
2023-03-01 20:27:38 +00:00
warn() {
printf "${BOLD}${YELLOW}$1${NORMAL}"
}
2019-07-03 21:08:59 +00:00
error() {
2023-03-01 20:27:38 +00:00
printf "${RED}$1${NORMAL}"
2019-07-03 21:08:59 +00:00
}
2020-05-14 04:36:01 +00:00
fatal() {
2023-03-01 20:27:38 +00:00
printf "${RED}$1${NORMAL}\n"
2020-05-14 04:36:01 +00:00
exit 1
}
2019-07-03 21:08:59 +00:00
log() {
2020-07-26 17:58:29 +00:00
msg="$1"
value="$2"
printf "@log ${BOLD}${YELLOW}$msg${GREEN}$value${NORMAL}\n"
2019-07-03 21:08:59 +00:00
}