RGB Colors
This commit is contained in:
parent
a34c00960b
commit
b90ccf8223
75
Functions/RGB-Terminal-Colors.bash
Executable file
75
Functions/RGB-Terminal-Colors.bash
Executable 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"
|
||||
}
|
Loading…
Reference in New Issue
Block a user