|
3 | 3 | Clear="\033[0m"; |
4 | 4 | # Suppressed Variables |
5 | 5 | if (( 1<2 )); then |
6 | | -# Colors |
7 | | -Gora="\033[1;97m" |
| 6 | +# ---------- |
| 7 | +# Colors. |
| 8 | +# Gora="\033[0;97m" |
| 9 | +# ---------- |
8 | 10 | # BG Colors. |
9 | | -BGRed="\033[1;41m"; |
10 | | -BGGreen="\033[1;42m"; |
11 | | -BGYelo="\033[1;43m"; |
| 11 | +# BGRed="\033[1;41m"; |
| 12 | +# BGGreen="\033[1;42m"; |
| 13 | +# BGYelo="\033[1;43m"; |
| 14 | +# BGBold="\033[1m"; |
| 15 | +# ---------- |
12 | 16 | # Status Colors. |
13 | | -StatusRed="${BGRed}${Gora}"; |
14 | | -StatusGreen="${BGGreen}${Gora}"; |
15 | | -StatusYelo="${BGYelo}${Gora}"; |
| 17 | +# StatusRed="${BGRed}${Gora}"; |
| 18 | +# StatusGreen="${BGGreen}${Gora}"; |
| 19 | +# StatusYelo="${BGYelo}${Gora}"; |
| 20 | +# ---------- |
16 | 21 | # Global variables. |
17 | | -Source="'([^']*)'"; |
| 22 | +Pattern="'([^']*)'"; |
| 23 | +# Color plate. |
| 24 | +COLOR_STRIP=( |
| 25 | + "\033[0;31m" # Red |
| 26 | + "\033[0;32m" # Green |
| 27 | + "\033[0;33m" # Yelo |
| 28 | + "\033[0;34m" # Blue |
| 29 | + "\033[0;35m" # Genta |
| 30 | + "\033[0;36m" # Cyan |
| 31 | +); |
18 | 32 | fi |
19 | 33 |
|
20 | | -# Colors |
21 | | -Red="\033[1;31m"; |
22 | | -Green="\033[1;32m"; |
23 | | -Yelo="\033[1;33m"; |
24 | | - |
25 | 34 | # say.gencolor() |
26 | 35 | # Gives you a random color code. |
27 | 36 | say.gencolor(){ |
28 | | - local STRIP=( |
29 | | - "\033[1;31m" |
30 | | - "\033[1;32m" |
31 | | - "\033[1;33m" |
32 | | - "\033[1;34m" |
33 | | - "\033[1;35m" |
34 | | - "\033[1;36m" |
35 | | - ); |
36 | | - echo "${STRIP[$(( RANDOM % ${#STRIP[@]} ))]}"; |
37 | | - return 0; |
| 37 | + echo "${COLOR_STRIP[$(( RANDOM % ${#COLOR_STRIP[@]} ))]}"; |
38 | 38 | } |
39 | 39 |
|
40 | | -# say(str) -> str |
41 | | -# Say strings with syntax highlighting feature. |
42 | | -say(){ |
43 | | - local String="${1}"; |
44 | | - local STRIP=(${String}); |
45 | | - local String=''; |
46 | | - for Uri in "${STRIP[@]}" |
| 40 | +# _say.colorizeString(str,@--gencolor,@--color <color>) ~ str |
| 41 | +# Create and returns you raw colorized strings. |
| 42 | +# Args: |
| 43 | +# str (str): takes string as arg. |
| 44 | +# --gencolor (obj,optional): adds colors randomly to syntax. |
| 45 | +# --color <color> (str,optional): adds given color to syntax. |
| 46 | +_say.colorizeString(){ |
| 47 | + local ARGString="${1}"; |
| 48 | + local isGenColorEnabled=1; |
| 49 | + local Sentence=(${ARGString}); |
| 50 | + local String; |
| 51 | + shift; |
| 52 | + case "${1}" in |
| 53 | + --gencolor) |
| 54 | + local isGenColorEnabled=0; |
| 55 | + ;; |
| 56 | + --color) |
| 57 | + local Color="${2}"; |
| 58 | + ;; |
| 59 | + esac |
| 60 | + for Shabd in "${Sentence[@]}" |
47 | 61 | do |
48 | | - if [[ "${Uri}" =~ ${Source} ]]; then |
| 62 | + if [[ "${Shabd}" =~ ${Pattern} ]]; then |
| 63 | + [[ "${isGenColorEnabled}" == 1 ]] || \ |
49 | 64 | local Color="$(say.gencolor)"; |
50 | | - local String+="${Color}${Uri}${Clear} "; |
51 | | - else local String+="${Uri} "; |
| 65 | + local String+="${Color}${Shabd}${Clear} "; |
| 66 | + else |
| 67 | + local String+="${Shabd} "; |
52 | 68 | fi |
53 | 69 | done |
| 70 | + echo "${String}"; |
| 71 | +} |
| 72 | + |
| 73 | +# say(str) ~ str |
| 74 | +# Say strings with syntax highlighting feature. |
| 75 | +say(){ |
| 76 | + local String="$(_say.colorizeString "${1}" --gencolor)"; |
54 | 77 | echo -e "${String}"; |
55 | | - return 0; |
56 | 78 | } |
57 | 79 |
|
58 | 80 | _status(){ |
59 | 81 | case "${1}" in |
60 | 82 | -error) |
61 | | - local Color="\033[1;31m"; |
62 | | - local StatusColor="${StatusRed}"; |
63 | | - ;; |
64 | | - -success) |
65 | | - local Color="\033[1;32m"; |
66 | | - local StatusColor="${StatusGreen}"; |
67 | | - ;; |
| 83 | + local Color="\033[0;31m"; |
| 84 | + local Header="ERR"; |
| 85 | + ;; |
68 | 86 | -warn) |
69 | | - local Color="\033[1;33m"; |
70 | | - local StatusColor="${StatusYelo}"; |
71 | | - ;; |
| 87 | + local Color="\033[0;33m"; |
| 88 | + local Header="WARN"; |
| 89 | + ;; |
| 90 | + -success) |
| 91 | + local Color="\033[0;32m"; |
| 92 | + local Header="INFO"; |
| 93 | + ;; |
72 | 94 | esac |
73 | | - local String="${2}"; |
74 | | - local xSTRIP=(${String}); |
75 | | - local String=''; |
76 | | - for Uri in "${xSTRIP[@]}" |
77 | | - do |
78 | | - if [[ "${Uri}" =~ ${Source} ]]; then |
79 | | - local String+="${Color}${Uri}${Clear} "; |
80 | | - else local String+="${Uri} "; |
81 | | - fi |
82 | | - done |
83 | | - echo -e "${StatusColor} INFO ${Clear} ➙ ${String}"; |
84 | | - return 0; |
| 95 | + local String="$(_say.colorizeString "${2}" --color "${Color}")"; |
| 96 | + echo -ne "[${Color} ${Header} ${Clear}]: "; |
| 97 | + echo -e "${String}"; |
85 | 98 | } |
86 | 99 |
|
87 | | -# say.error(str) -> str |
| 100 | +# say.error(str) ~ str |
88 | 101 | # Says error to terminal. |
89 | 102 | say.error(){ |
90 | 103 | _status -error "${@}"; |
91 | 104 | } |
92 | 105 |
|
93 | | -# say.warn(str) -> str |
| 106 | +# say.warn(str) ~ str |
94 | 107 | # Says warning to terminal. |
95 | 108 | say.warn(){ |
96 | 109 | _status -warn "${@}"; |
97 | 110 | } |
98 | 111 |
|
99 | | -# say.success(str) -> str |
| 112 | +# say.success(str) ~ str |
100 | 113 | # Says success to terminal. |
101 | 114 | say.success(){ |
102 | 115 | _status -success "${@}"; |
103 | 116 | } |
104 | 117 |
|
105 | | -# say.checkStatus(status) -> str |
| 118 | +# log(str) ~ str |
| 119 | +# Say log to the user. |
| 120 | +log(){ |
| 121 | + case "${?}" in |
| 122 | + 0) |
| 123 | + _status -success "${@}"; |
| 124 | + ;; |
| 125 | + *) |
| 126 | + _status -error "${@}"; |
| 127 | + ;; |
| 128 | + esac |
| 129 | +} |
| 130 | + |
| 131 | +# say.checkStatus(status) ~ str |
106 | 132 | # This prints success or failure according to exit code. |
107 | 133 | # Args: |
108 | 134 | # status (int) > takes exit code. |
109 | 135 | say.checkStatus(){ |
110 | 136 | if [[ "${1}" == 0 ]]; then |
111 | | - echo -e " ➙ ${StatusGreen} SUCCESS ${Clear}"; |
| 137 | + echo -e " ~ [${COLOR_STRIP[1]} SUCCESS ${Clear}]"; |
112 | 138 | else |
113 | | - echo -e " ➙ ${StatusRed} FAILED ${Clear}"; |
| 139 | + echo -e " ~ [${COLOR_STRIP[0]} FAILED ${Clear}]"; |
114 | 140 | exit 1; |
115 | 141 | fi |
116 | 142 | } |
0 commit comments