LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Font Effects in 8-Bit and 24-Bit Colour Representations (https://www.linuxquestions.org/questions/linux-newbie-8/font-effects-in-8-bit-and-24-bit-colour-representations-4175724043/)

Faki 04-13-2023 07:13 PM

Font Effects in 8-Bit and 24-Bit Colour Representations
 
I want to use 8-Bit and 24-Bit colours in terminal, and have seen some different versions.

Code:

code="\e[38;5;${if}m"
code="\e[38;5;${ir};${ig};${ib}m"

I am unsure about the second number 5, sometimes it is 2. Have read that it is also related to Font Effects.

Have also noticed that the Font Effect only affects the foreground and can be included separately (e.g. \e[5m). Is this correct ?

Code:

code="\e[5m\e[38;5;${ir};${ig};${ib}m"

teckk 04-13-2023 09:35 PM

Example:
Code:

green="\033[0;32m"
blue="\033[0;34m"
cyan="\033[0;36m"
red="\033[0;31m"
grey="\033[0;37m"
white="\033[1;37m"
bcyan="\033[1;36m"
bgreen="\033[1;32m"
bblue="\033[1;34m"
bred="\033[1;31m"
bgrey="\033[1;30m"
clr="\033[0m"

colors=($green $blue $cyan $red $grey $white $bcyan $bgreen $bblue $bred $bgrey $clr)

for i in "${colors[@]}" ;do
    printf "${i}Hello${clr} World\n"
done


Michael Uplawski 04-14-2023 03:54 AM

Bold: "\033[01m"
Underline: "\033[04m"

styled text: [style-code][text]\033[0m

It is unimportant if [text] is already colored. That is all I know. If – together with Teck's example – it is not sufficient, then I have not understood the OP and am ready to learn something.

Also, ... which style should possibly affect something else than the foreground?

teckk 04-14-2023 08:06 AM

Code:

#!/usr/bin/bash

#Playing with bash colors.

green="\033[0;32m"
blue="\033[0;34m"
cyan="\033[0;36m"
red="\033[0;31m"
grey="\033[0;37m"
white="\033[1;37m"
bcyan="\033[1;36m"
bgreen="\033[1;32m"
bblue="\033[1;34m"
bred="\033[1;31m"
bgrey="\033[1;30m"

colors=($green $blue $cyan $red $grey $white $bcyan $bgreen $bblue $bred $bgrey)

spacing=${1:-10}
scroll=${1:-0}
screenlines=$(expr $(tput lines) - 1 + $scroll)
screencols=$(expr $(tput cols) / 2)

chars=(0 1)
count=${#chars[@]}
colorcount=${#colors[@]}

trap "tput sgr0; clear; exit" SIGTERM SIGINT

clear
tput cup 0 0
while :; do
    for ((i=1; i<=$screenlines; i++)); do
        for ((j=1; j<=$screencols; j++)); do
            rand=$(($RANDOM%$spacing))
            case $rand in
                0) printf "${colors[$RANDOM%$colorcount]}${chars[$RANDOM%$count]} " ;;
                1) printf "  " ;;
                *) printf "\033[2C" ;;
            esac
        done
        printf "\n"
    done
    printf "${colors[0]}Computing the exact value for pi, please wait."
    tput cup 0 0
    ran=".$((1 + RANDOM % 3))"
    sleep "$ran"
done



All times are GMT -5. The time now is 07:02 PM.