Bash_Scripts/Templates/Functions/RGB-Terminal-Colors.bash
Price Hiller 1bdb2ad075 Copyright
2021-08-04 01:21:11 -05:00

83 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# Copyright 2021, Price Hiller - All Rights Reserved
#
# Copying, distribution, usage, or modification of this file or the following source code, via any
# method is strictly prohibited without the explicit written consent of Price Hiller (philler3138@gmail.com)
# The following file contains proprietary and confidential content
#
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"
}