RGB Colors

This commit is contained in:
Price Hiller 2021-07-31 18:45:02 -05:00
parent a34c00960b
commit b90ccf8223

View File

@ -0,0 +1,75 @@
#!/bin/bash
rgb () {
# Echo a color printf to the terminal awaiting an actual echo to be colored
# should be used with reset after coloring a string
#
# Positional Arguments:
# red <type: int> <position: 1> <required: true>
# - The red value from 0 to 255
# green <type: int> <position: 2> <required: true>
# - The green value from 0 to 255
# blue <type: int> <position: 2> <required: true>
# - The blue value from 0 to 255
#
# Usage:
# echo_rgb 10 80 3 && echo "hello" && reset
#
# POSIX Compliant:
# N/A
#
red="${1}"
green="${2}"
blue="${3}"
printf "\e[0;38;2;%s;%s;%sm" "${red}" "${green}" "${blue}"
}
echo_rgb() {
# Echo a colored string to the terminal based on rgb values
#
# Positional Arguments:
#
# message <type: string> <position: 1> <required: true>
# - The message to be printed to stdout
# red <type: int> <position: 2> <required: true>
# - The red value from 0 to 255
# green <type: int> <position: 3> <required: true>
# - The green value from 0 to 255
# blue <type: int> <position: 4> <required: true>
# - The blue value from 0 to 255
#
# Usage:
# echo_rgb 10 80 3 "Yep"
#
# POSIX Compliant:
# N/A
#
local red
local green
local blue
local input
input="${1}"
red="${2}"
green="${3}"
blue="${4}"
printf "\e[0;38;2;%s;%s;%sm%s\e[m\n" "${red}" "${green}" "${blue}" "${input}"
}
reset() {
# Reset colors in the terminal to default
#
# Usage:
# reset
#
# POSIX Compliant:
# N/A
#
printf "\e[m\n"
}