#!/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 # - The red value from 0 to 255 # green # - The green value from 0 to 255 # blue # - 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 # - The message to be printed to stdout # red # - The red value from 0 to 255 # green # - The green value from 0 to 255 # blue # - 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" }