[ RGB Out ] - Detect if in tty
This commit is contained in:
parent
0cbcda179f
commit
9e9e73400b
@ -31,7 +31,11 @@ echo_rgb() {
|
|||||||
green="${3}"
|
green="${3}"
|
||||||
blue="${4}"
|
blue="${4}"
|
||||||
|
|
||||||
|
if [ -t 1 ]; then
|
||||||
printf "\e[0;38;2;%s;%s;%sm%s\e[m\n" "${red}" "${green}" "${blue}" "${input}"
|
printf "\e[0;38;2;%s;%s;%sm%s\e[m\n" "${red}" "${green}" "${blue}" "${input}"
|
||||||
|
else
|
||||||
|
printf "%s\n" "${input}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
rgb() {
|
||||||
|
|
||||||
rgb () {
|
|
||||||
# Echo a color printf to the terminal awaiting an actual echo to be colored
|
# Echo a color printf to the terminal awaiting an actual echo to be colored
|
||||||
# should be used with reset after coloring a string
|
# should be used with reset after coloring a string
|
||||||
#
|
#
|
||||||
@ -28,7 +26,6 @@ rgb () {
|
|||||||
printf "\e[0;38;2;%s;%s;%sm" "${red}" "${green}" "${blue}"
|
printf "\e[0;38;2;%s;%s;%sm" "${red}" "${green}" "${blue}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
echo_rgb() {
|
echo_rgb() {
|
||||||
# Echo a colored string to the terminal based on rgb values
|
# Echo a colored string to the terminal based on rgb values
|
||||||
#
|
#
|
||||||
@ -69,7 +66,6 @@ echo_rgb() {
|
|||||||
local bg_green
|
local bg_green
|
||||||
local bg_blue
|
local bg_blue
|
||||||
|
|
||||||
|
|
||||||
input="${1}"
|
input="${1}"
|
||||||
red="${2}"
|
red="${2}"
|
||||||
green="${3}"
|
green="${3}"
|
||||||
@ -79,17 +75,18 @@ echo_rgb() {
|
|||||||
bg_blue="${7}"
|
bg_blue="${7}"
|
||||||
|
|
||||||
for num in "${@:2}"; do
|
for num in "${@:2}"; do
|
||||||
[[ ! "${num}" =~ [0-9] ]] \
|
[[ ! "${num}" =~ [0-9] ]] &&
|
||||||
&& echo "Given RGB value was not a number, received ${num}" \
|
echo "Given RGB value was not a number, received ${num}" &&
|
||||||
&& return 1
|
return 1
|
||||||
[[ "${num}" -gt 255 ]] \
|
[[ "${num}" -gt 255 ]] &&
|
||||||
&& echo "Given RGB value must be less than 255, received ${num}" \
|
echo "Given RGB value must be less than 255, received ${num}" &&
|
||||||
&& return 1
|
return 1
|
||||||
[[ "${num}" -lt 0 ]] \
|
[[ "${num}" -lt 0 ]] &&
|
||||||
&& echo "Given RGB value must be more than 0, received ${num}" \
|
echo "Given RGB value must be more than 0, received ${num}" &&
|
||||||
&& return 1
|
return 1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ -t 1 ]; then
|
||||||
if [ -n "${5}" ]; then
|
if [ -n "${5}" ]; then
|
||||||
[[ -z "${6}" ]] && echo "A value must be passed for bg_green" && return 1
|
[[ -z "${6}" ]] && echo "A value must be passed for bg_green" && return 1
|
||||||
[[ -z "${7}" ]] && echo "A value must be passed for bg_blue" && return 1
|
[[ -z "${7}" ]] && echo "A value must be passed for bg_blue" && return 1
|
||||||
@ -98,6 +95,9 @@ echo_rgb() {
|
|||||||
else
|
else
|
||||||
printf "\033[0;38;2;%s;%s;%sm%s\033[m\n" "${red}" "${green}" "${blue}" "${input}"
|
printf "\033[0;38;2;%s;%s;%sm%s\033[m\n" "${red}" "${green}" "${blue}" "${input}"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
printf "%s\n" "${input}"
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user