add text in colors

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2025-05-07 00:08:11 +02:00
commit e398a50337
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
4 changed files with 38 additions and 7 deletions

View file

@ -1,8 +1,14 @@
#!/bin/bash
# red delete
# orange check-no-delete
# orange check-no-create
# green create
[[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://git.g3e.fr/H6N/tools/raw/branch/main/libs/shflags)"
. ./lib/vpc.sh
. ./lib/colors.sh
DRY_RUN="1"
SIMULATION="1"

View file

@ -1,5 +1,11 @@
#!/bin/bash
. ./lib/vpc.sh
export TERM=xterm-256color
delete_vpc "${1}"
for i in {0..255}; do
echo -e "\033[38;5;${i}m$i\t"
if (( ($i + 1) % 10 == 0 )); then echo; fi
done
echo -e "\e[0m"
printf "\033[38;5;208mTexte en orange (code 208)\033[0m\n"

14
lib/colors.sh Normal file
View file

@ -0,0 +1,14 @@
#!/bin/bash
COLOR_RED="196"
COLOR_ORANGE="208"
COLOR_GREEN="154"
COLOR_GREY="246"
function print_in_color {
color="${1}"
text="${2}"
echo -e "\033[38;5;${color}m${text}\e[0m"
}

View file

@ -2,16 +2,15 @@
. ./lib/db.sh
. ./lib/netns.sh
. ./lib/colors.sh
function check_vpc_exist {
vpc_name=${1}
echo "#check if the vpc ${vpc} exist"
echo " -> check in file"
echo " -> check in linux"
print_in_color "${COLOR_GREY}" "Check in db if ${vpc_name} exist"
check_in_db vpc "${vpc_name}"
[ "$?" -eq "0" ] || return 1
print_in_color "${COLOR_GREY}" "Check in linux if ${vpc_name} exist"
check_netns "${vpc_name}"
[ "$?" -eq "0" ] || return 1
return 0
@ -22,10 +21,14 @@ function create_vpc {
vpc_name="${2}"
check_vpc_exist "${vpc_name}"
[ "$?" -eq "0" ] || \
[ "$?" -eq "0" ] && \
{
print_in_color "${COLOR_ORANGE}" "Create ${vpc_name}"
} || \
{
add_in_db "vpc" "${vpc_name}"
create_netns "${vpc_name}"
print_in_color "${COLOR_GREEN}" "Create ${vpc_name}"
}
}
@ -34,6 +37,8 @@ function delete_vpc {
dryrun="${1}"
vpc_name="${2}"
print_in_color "${COLOR_RED}" "Delete ${vpc_name}"
delete_in_db "vpc" "${vpc_name}"
delete_netns "${vpc_name}"