kodie
8/25/2016 - 4:51 PM

Functions to display styled text

Functions to display styled text

function txtStyle {
  local color
  local background
  local style
  local output

  case "$1" in
    "black") color="30" ;;
    "red") color="31" ;;
    "green") color="32" ;;
    "yellow") color="33" ;;
    "blue") color="34" ;;
    "magenta") color="35" ;;
    "cyan") color="36" ;;
    "white") color="37" ;;
    *) color="37" ;;
  esac

  case "$2" in
    "black") background="40" ;;
    "red") background="41" ;;
    "green") background="42" ;;
    "yellow") background="43" ;;
    "blue") background="44" ;;
    "magenta") background="45" ;;
    "cyan") background="46" ;;
    "white") background="47" ;;
    *) background="40" ;;
  esac

  case "$3" in
    "normal") style="0" ;;
    "bold") style="1" ;;
    "underline") style="4" ;;
    "blink") style="5" ;;
    *) style="0" ;;
  esac

  output="\e["$style";"$color";"$background"m"
  echo $output
}

function txt {
  local color=$(txtStyle $2 $3 $4)
  local def=$(txtStyle)
  printf "$color$1$def\n"
}

txt "Here is some styled text!" cyan magenta bold