dotfiles/script_helpers/printing.sh

45 lines
751 B
Bash

#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
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)"
DIM="\e[2m"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
warn() {
printf "${BOLD}${YELLOW}$1${NORMAL}"
}
error() {
printf "${RED}$1${NORMAL}"
}
fatal() {
printf "${RED}$1${NORMAL}\n"
exit 1
}
log() {
msg="$1"
value="$2"
printf "@log ${BOLD}${YELLOW}$msg${GREEN}$value${NORMAL}\n"
}