10

I'm Creating a Login Screen when I start my CLI Arch Linux and I build a script on the file

/etc/bash.bashrc

Like as it follows below:

#COMMANDS CREATED INSIDE /ETC/BASH.BASHRC FILE
# USING ANSI COLORS
RED="\e[31m"
ORANGE="\e[33m"
BLUE="\e[94m"
GREEN="\e[92m"
STOP="\e[0m"


# LOGIN SCREEN MESSAGE 
screenfetch
printf "${GREEN}"
printf "=================================\n"
printf "${ORANGE}"
figlet -w 200 -f standard "F4NT0 ARCH LINUX"
printf "${BLUE}"
figlet -w 200 -f  small "CLI Operational System"
printf "${GREEN}"
printf "=================================\n"
printf "${STOP}"

In the code above, I build the variables who calls the colors and I let "leak" on the messages created with the figlet program using the printf.

This way I can color the messages until the last variable call(the message below stay with the color i call in the variable above), when I call the next variable,the code change the color from the next message and so on until the STOP variable who stop the leaking of the colors.

The Login Letters

I like how it works in my Arch, but programable way I find it "dirty"...

There is a way to add colors(ANSI,tput or others) in the figlet command to become more adequate to add colors inside Scripts in Unix/Linux?

2 Answers 2

9

The way I show In this Question is the Best Way to Put Colors on Figlet, the Way a color is putting before the commands is the Only way I find to Make it work, And after I call the next Color,the next line will be Change to The New Color!!

If anyone want to Know, the Way I call the colors is using the ANSI color codes, like Below:

Regular Colors:

  • \e[30m = Black
  • \e[31m = Red
  • \e[32m = Green
  • \e[33m = Yellow
  • \e[34m = Blue
  • \e[35m = Purple
  • \e[36m = Cyan
  • \e[37m = White

Light Colors:

  • \e[90 = Light Black
  • \e[91 = Light Red
  • \e[92 = Light Green
  • \e[93 = Light Yellow
  • \e[94 = Light Blue
  • \e[95 = Light Purple
  • \e[96 = Light Cyan
  • \e[97 = Light White

The way I use isn´t the only way, not even the complete one

For the Complete Informations About ANSI colors, read this Site:

https://misc.flogisoft.com/bash/tip_colors_and_formatting

About The Variables:

  • I put the color name all in Caps because is the best way to avoid Confusion

GREEN="\e[92m"

  • To call the Variable Created, you need to catch the value of the Vaiable, Using the ${} construction

${GREEN}

  • To make the Color out before the command, you need to use printf to leak the Color(I use Printf but I think echo works too).

printf "${GREEN}"

  • The Next Line who Print Something on the Screen Will have the Color of the Variable.

printf "${GREEN}"

figlet -f standard "This Will Be Green"

The Text Should Be Like This:

Test

  • To Stop the Color Leak Inside Where it Shouldn´t, there´s Two Steps:
    • If you want to put a New Color, Just Call the New Color
    • If you want to Stop the Color, Use the Following Variable:

      STOP="\e[0m"

      • Put the Stop in the End where after that you Don´t want to Change the color like that:

      printf "${STOP}"

2

I would recommend using this pattern:

RED_B='\e[1;91m'
GREEN_B='\e[1;92m'
YELLOW_B='\e[1;93m'
BLUE_B='\e[1;94m'
PURPLE_B='\e[1;95m'
CYAN_B='\e[1;96m'
WHITE_B='\e[1;97m'
RESET='\e[0m'

red() { echo -e "${RED_B}${1}${RESET}"; }
green() { echo -e "${GREEN_B}${1}${RESET}"; }
yellow() { echo -e "${YELLOW_B}${1}${RESET}"; }
blue() { echo -e "${BLUE_B}${1}${RESET}"; }
purple() { echo -e "${PURPLE_B}${1}${RESET}"; }
cyan() { echo -e "${CYAN_B}${1}${RESET}"; }
white() { echo -e "${WHITE_B}${1}${RESET}"; }

You can then pass the figlet command as an argument to the color functions:

bash-5.0# green "$(figlet -f big "Hello!")"

enter image description here

1
  • 1
    I just noticed Armbian has nicely colored bigtext ASCII hostnames on ssh/login, they use toilet for this. From before I remember figlet can't layout text with ANSI embedded. So coloring works only per line, unless you write it as a post-process filter on figlet output somehow.
    – mpe
    Commented Feb 5, 2022 at 0:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .