Colors upgrade

This commit is contained in:
Roman Ožana 2023-11-21 17:54:55 +01:00
parent 4910216ec2
commit c2b01dfb75
4 changed files with 49 additions and 60 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 121 KiB

View File

@ -5,37 +5,35 @@
# Author: Roman Ožana <roman@ozana.cz> # Author: Roman Ožana <roman@ozana.cz>
# License: MIT # License: MIT
# Basic colors # Black and white
export BLACK='\033[0;30m' export BLACK='\033[0;30m'
export WHITE='\033[0;37m'
export GRAY='\033[0;90m' export GRAY='\033[0;90m'
export NC='\033[0m' # reset color
# Basic colors
export RED='\033[0;31m' export RED='\033[0;31m'
export GREEN='\033[0;32m' export GREEN='\033[0;32m'
export BLUE='\033[0;34m' export BLUE='\033[0;34m'
export YELLOW='\033[0;33m' export YELLOW='\033[0;33m'
export MAGENTA='\033[0;35m' export MAGENTA='\033[0;35m'
export CYAN='\033[0;36m' export CYAN='\033[0;36m'
export WHITE='\033[0;37m'
export NC='\033[0m' # reset color
# Light colors # Bright colors
export LIGHT_GRAY='\033[0;37m' export BRIGHT_RED='\033[0;91m'
export LIGHT_RED='\033[0;91m' export BRIGHT_GREEN='\033[0;92m'
export LIGHT_GREEN='\033[0;92m' export BRIGHT_BLUE='\033[0;94m'
export LIGHT_BLUE='\033[0;94m' export BRIGHT_YELLOW='\033[0;93m'
export LIGHT_YELLOW='\033[0;93m' export BRIGHT_MAGENTA='\033[0;95m'
export LIGHT_MAGENTA='\033[0;95m' export BRIGHT_CYAN='\033[0;96m'
export LIGHT_CYAN='\033[0;96m'
# Bold basic colors # Bold colors
export BOLD_BLACK='\033[1;30m'
export BOLD_GRAY='\033[1;90m'
export BOLD_RED='\033[1;31m' export BOLD_RED='\033[1;31m'
export BOLD_GREEN='\033[1;32m' export BOLD_GREEN='\033[1;32m'
export BOLD_BLUE='\033[1;34m' export BOLD_BLUE='\033[1;34m'
export BOLD_YELLOW='\033[1;33m' export BOLD_YELLOW='\033[1;33m'
export BOLD_MAGENTA='\033[1;35m' export BOLD_MAGENTA='\033[1;35m'
export BOLD_CYAN='\033[1;36m' export BOLD_CYAN='\033[1;36m'
export BOLD_WHITE='\033[1;37m'
# Styles # Styles
export BOLD='\033[1m' export BOLD='\033[1m'

View File

@ -5,40 +5,53 @@ source colors.sh
echo "-----------------------------------------------------------------------------" echo "-----------------------------------------------------------------------------"
# there can be a function that uses the colors # there can be a function that uses the colors
function info() { printf "${MAGENTA}$@${NC}\n"; } function info() { printf "${BOLD_CYAN}%s${NC}\n" "$@"; }
function warn() { printf "${BOLD_YELLOW}$@${NC}\n"; } function warn() { printf "${BOLD_YELLOW}%s${NC}\n" "$@"; }
function error() { printf "${BOLD_RED}$@${NC}\n"; } function error() { printf "${BOLD_RED}%s${NC}\n" "$@"; }
function debug() { printf "${BOLD_GRAY}$@${NC}\n"; } function debug() { printf "${BOLD_GRAY}%s${NC}\n" "$@"; }
function success() { printf "${BOLD_GREEN}$@${NC}\n"; } function success() { printf "${BOLD_GREEN}%s${NC}\n" "$@"; }
info "This is a info test" info "[INFO] This is info text"
warn "This is a warn test" warn "[WARN] This is warn text"
error "This is a error test" error "[ERROR] This is error text"
debug "This is a debug test" debug "[DEBUG] This is debug text"
echo "-----------------------------------------------------------------------------"
echo -e "${GRAY}-----------------------------------------------------------------------------${NC}"
## Color print function ## Color print function
function cprint() { printf "$1$2${NC}\n"; } function color() { printf "$1%s${NC}\n" "$2";}
cprint $RED "This is red text" color "$RED" "This is red text"
cprint $BOLD_MAGENTA "Bold magenta text" color "$BOLD_MAGENTA" "Bold magenta text"
cprint $BOLD_YELLOW "Bold yellow text" color "$BOLD_YELLOW" "Bold yellow text"
echo "-----------------------------------------------------------------------------" echo -e "${GRAY}-----------------------------------------------------------------------------${NC}"
for color in $BLACK $GRAY $RED $GREEN $BLUE $YELLOW $MAGENTA $CYAN $WHITE; do echo -e "${BLACK}Black color text${NC}"
printf "$color%s${NC}\n" "Test color text" echo -e "${WHITE}White color text${NC}"
done
echo "-----------------------------------------------------------------------------" echo -e "${GRAY}-----------------------------------------------------------------------------${NC}\n\n"
# Basic colors
echo -e "${BLACK}BLACK${NC}, ${GRAY}GRAY${NC} or ${WHITE}WHITE${NC} color text"
echo -e "${RED}RED${NC} or ${BRIGHT_RED}BRIGHT_RED${NC} color text"
echo -e "${GREEN}GREEN${NC} or ${BRIGHT_GREEN}BRIGHT_GREEN${NC} color text"
echo -e "${BLUE}BLUE${NC} or ${BRIGHT_BLUE}BRIGHT_BLUE${NC} color text"
echo -e "${YELLOW}YELLOW${NC} or ${BRIGHT_YELLOW}BRIGHT_YELLOW${NC} color text"
echo -e "${MAGENTA}MAGENTA${NC} or ${BRIGHT_MAGENTA}BRIGHT_MAGENTA${NC} color text"
echo -e "${CYAN}CYAN${NC} or ${BRIGHT_CYAN}BRIGHT_CYAN${NC} color text"
echo -e "\n\n${GRAY}-----------------------------------------------------------------------------${NC}"
# with colors.sh sourced, you can use the constants # with colors.sh sourced, you can use the constants
echo "${RED}This is red text${NC} and this is ${GREEN}green ${BLINK}blink${NC} text${NC}" echo -e "${RED}This is ${BOLD}bold red text${NC} and this is ${GREEN}green ${BLINK}blink${NC} text${NC}"
echo "this is ${MAGENTA}magenta ${BLINK}blink${NC} text${NC}" echo -e "this is ${MAGENTA}magenta ${BLINK}blink${NC} text${NC}"
echo -e "${GRAY}-----------------------------------------------------------------------------${NC}"
echo "-----------------------------------------------------------------------------"
# Add color to the output of a command # Add color to the output of a command
{ {

View File

@ -21,28 +21,6 @@ source colors.sh
echo "This is ${RED}red text${NC}" echo "This is ${RED}red text${NC}"
``` ```
## Contants
- `GRAY` - for gray
- `LIGHT_GRAY` - for light_gray
- `YELLOW` - for yellow
- `LIGHT_YELLOW` - for light yellow
- `GREEN` - for green
- `LIGHT_GREEN` - for light green
- `RED` - for red
- `LIGHT_RED` - for light red
- `BLUE` - for blue
- `LIGHT_BLUE` - for light blue
- `MAGENTA` - for magenta
- `LIGHT_MAGENTA` - for light magenta
- `CYAN` - for cyan
- `WHITE` - for white
- `BLACK` - for black
- `BOLD` - for bold
- `UNDERLINE` - for underline
- `BLINK` - for blink
- `NC` - for no colors (reset)
## License ## License
MIT MIT