From e398a50337359005f28d310baf52eb3cd0c03224 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Wed, 7 May 2025 00:08:11 +0200 Subject: [PATCH] add text in colors Signed-off-by: GnomeZworc --- agent.sh | 6 ++++++ delete_vpc.sh | 10 ++++++++-- lib/colors.sh | 14 ++++++++++++++ lib/vpc.sh | 15 ++++++++++----- 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 lib/colors.sh diff --git a/agent.sh b/agent.sh index 284eb60..2f836c3 100644 --- a/agent.sh +++ b/agent.sh @@ -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" diff --git a/delete_vpc.sh b/delete_vpc.sh index 81acab2..ae9dac9 100644 --- a/delete_vpc.sh +++ b/delete_vpc.sh @@ -1,5 +1,11 @@ #!/bin/bash -. ./lib/vpc.sh +export TERM=xterm-256color -delete_vpc "${1}" \ No newline at end of file +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" \ No newline at end of file diff --git a/lib/colors.sh b/lib/colors.sh new file mode 100644 index 0000000..e3678d7 --- /dev/null +++ b/lib/colors.sh @@ -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" + +} \ No newline at end of file diff --git a/lib/vpc.sh b/lib/vpc.sh index bca59f7..ecd2d20 100644 --- a/lib/vpc.sh +++ b/lib/vpc.sh @@ -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}"