Toutes les couleurs et styles Bash

Ce script permet d’afficher toutes les couleurs et tous les styles d’écriture possibles dans un terminal. Cette version permet d’afficher les paramètres de style sur le rendu final.

#!/bin/bash

# -----------------------------------------------
# Resize the terminal if it's not in full screen
# -----------------------------------------------
resizeWindow()
{
echo -en "\e[$1;$2;$3t"
}

# -----------------------------------------------
# Example
# -----------------------------------------------
colorExample()
{
echo -e "\n \033[0;4;33mCommand example :\033[0m"
echo " echo -e '\033[40;6;34m This is an example. \033[0m Cool !'"
echo -e "\n \033[0;4;33mResult :\033[0m"
echo -e " \033[40;6;34m This is an example. \033[0m cool !"
echo -e "\n"
echo -e "——————————————————————————————————————————————————————————————————————————————————————————————— \n"
}

echo -en "Background COLOR : \033[0m 0 \033[0m \n"

echo "-----------------------------------------------------------------------------------------------"

echo -en " STYLE |\033[1;30m Black\033[0m |\033[1;31m Red\033[0m |\033[1;32m Green\033[0m |\033[1;33m Yellow\033[0m |\033[1;34m Blue\033[0m |\033[1;35m Pink\033[0m |\033[1;36m Cyan\033[0m |\033[1;37m White\033[0m\n"

echo "-----------------------------------------------------------------------------------------------"

# -----------------------------------------------
# Display all color in a table
# -----------------------------------------------
colorView()
{
# Display and Layout
echo -en "Background COLOR : \033[${1}m ${1} \033[0m \n"
echo "-----------------------------------------------------------------------------------------------"
echo -en " STYLE |\033[1;30m Black\033[0m |\033[1;31m Red\033[0m |\033[1;32m Green\033[0m |\033[1;33m Yellow\033[0m |\033[1;34m Blue\033[0m |\033[1;35m Pink\033[0m |\033[1;36m Cyan\033[0m |\033[1;37m White\033[0m\n"
echo "-----------------------------------------------------------------------------------------------"

# Style parsing (bold, underline, strike, highlight)
for ((style=1;style<=9;style++)) do

# 3, 6, 8 style doing nothing
if [ $style != 3 ] && [ $style != 6 ] && [ $style != 8 ]; then

echo -en "Style \033[${style}m${style}\033[0m "

# Text color parsing
for ((fg=30;fg<=37;fg++)); do

echo -en "\033[${1};${style};${fg}m[${bg};${style};${fg}m "

done

# Default Value
echo -e "\033[0m"
fi
done

echo -en "—————————————————————————————————————————————————————————————————————————————————————————————— \n"
}

# -----------------------------------------------
# Main Program
# -----------------------------------------------
resizeWindow 8 100 97
colorExample
colorView 0 # no background
for ((bg=40;bg<=48;bg++)); do
colorView $bg
done
> Partager <