## Color functions [@bashly-upgrade colors] ## This file is a part of Bashly standard library ## ## Usage: ## Use any of the functions below to color or format a portion of a string. ## ## echo β€œbefore $(red this is red) after” ## echo β€œbefore $(green_bold this is green_bold) after” ## ## Color output will be disabled if β€˜NO_COLOR` environment variable is set ## in compliance with no-color.org/ ## ## In case you wish to enable auto detection for color output based on the ## terminal being interactive (TTY), call `enable_auto_colors` in your ## `src/initialize.sh` (Run `bashly add hooks` to add this file). ## enable_auto_colors() {

## If NO_COLOR has not been set and stdout is not a TTY, disable colors
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
  NO_COLOR=1
fi

}

print_in_color() {

local color="$1"
shift
if [[ "${NO_COLOR:-}" == "" ]]; then
  printf "$color%b\e[0m\n" "$*"
else
  printf "%b\n" "$*"
fi

}

red() { print_in_color β€œe[31m” β€œ$*”; } green() { print_in_color β€œe[32m” β€œ$*”; } yellow() { print_in_color β€œe[33m” β€œ$*”; } blue() { print_in_color β€œe[34m” β€œ$*”; } magenta() { print_in_color β€œe[35m” β€œ$*”; } cyan() { print_in_color β€œe[36m” β€œ$*”; } black() { print_in_color β€œe[30m” β€œ$*”; } white() { print_in_color β€œe[37m” β€œ$*”; }

bold() { print_in_color β€œe[1m” β€œ$*”; } underlined() { print_in_color β€œe[4m” β€œ$*”; } bold_underlined() { print_in_color β€œe[1;4m” β€œ$*”; }

red_bold() { print_in_color β€œe[1;31m” β€œ$*”; } green_bold() { print_in_color β€œe[1;32m” β€œ$*”; } yellow_bold() { print_in_color β€œe[1;33m” β€œ$*”; } blue_bold() { print_in_color β€œe[1;34m” β€œ$*”; } magenta_bold() { print_in_color β€œe[1;35m” β€œ$*”; } cyan_bold() { print_in_color β€œe[1;36m” β€œ$*”; } black_bold() { print_in_color β€œe[1;30m” β€œ$*”; } white_bold() { print_in_color β€œe[1;37m” β€œ$*”; }

red_underlined() { print_in_color β€œe[4;31m” β€œ$*”; } green_underlined() { print_in_color β€œe[4;32m” β€œ$*”; } yellow_underlined() { print_in_color β€œe[4;33m” β€œ$*”; } blue_underlined() { print_in_color β€œe[4;34m” β€œ$*”; } magenta_underlined() { print_in_color β€œe[4;35m” β€œ$*”; } cyan_underlined() { print_in_color β€œe[4;36m” β€œ$*”; } black_underlined() { print_in_color β€œe[4;30m” β€œ$*”; } white_underlined() { print_in_color β€œe[4;37m” β€œ$*”; }