Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Bash
Posted by: Сергей Шевченко
Added: Dec 25, 2019 11:53 AM
Views: 82
  1. #!/bin/bash
  2.  
  3. set -eux
  4.  
  5. NC='\e[0m' # No Color
  6. BLACK='\e[0;30m'
  7. BLUE='\e[0;34m'
  8. BROWN='\e[0;33m'
  9. CYAN='\e[0;36m'
  10. GRAY='\e[0;30m'
  11. GREEN='\e[0;32m'
  12. PURPLE='\e[0;35m'
  13. RED='\e[0;31m'
  14. WHITE='\e[1;37m'
  15. YELLOW='\e[1;33m'
  16.  
  17.  
  18. function addLogMessage {
  19.     set +x
  20.     MESSAGE=${1}
  21.     COLOR=''
  22.  
  23.     if [[ ! -n ${2+set} ]]; then
  24.         COLOR=${CYAN}
  25.     else
  26.         COLOR=${2}
  27.     fi
  28.  
  29.     # Делаем красивую рамку вокруг сообщения
  30.     COUNT_SYMBOLS=$(echo ${MESSAGE} | wc -m)
  31.     PAST_BORDER_SYMBOLS=''
  32.     PAST_SPACES_SYMBOLS=''
  33.     for ((i=1; i<=${COUNT_SYMBOLS}; i++)); do
  34.         PAST_BORDER_SYMBOLS="${PAST_BORDER_SYMBOLS}*";
  35.         PAST_SPACES_SYMBOLS="${PAST_SPACES_SYMBOLS} ";
  36.     done
  37.  
  38.     echo -e "\n\n\n"
  39.     echo -e "${COLOR}*************${PAST_BORDER_SYMBOLS}*************${NC}"
  40.     echo -e "${COLOR}*            ${PAST_SPACES_SYMBOLS}            *${NC}"
  41.     echo -e "${COLOR}*            ${MESSAGE}            *${NC}"
  42.     echo -e "${COLOR}*            ${PAST_SPACES_SYMBOLS}            *${NC}"
  43.     echo -e "${COLOR}*************${PAST_BORDER_SYMBOLS}*************${NC}\n"
  44.     set -x
  45. }