LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-13-2023, 07:13 PM   #1
Faki
Member
 
Registered: Oct 2021
Posts: 574

Rep: Reputation: Disabled
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"
 
Old 04-13-2023, 09:35 PM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,147
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
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
 
Old 04-14-2023, 03:54 AM   #3
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622
Blog Entries: 40

Rep: Reputation: Disabled
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?

Last edited by Michael Uplawski; 04-14-2023 at 03:57 AM. Reason: erm ...
 
Old 04-14-2023, 08:06 AM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,147
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
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
 
1 members found this post helpful.
  


Reply

Tags
bash



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Slackware Terminal vs Putty Terminal Font and Colour Palette dalacor Slackware 11 08-11-2022 05:27 AM
how to change open terminal background colour and font size and color in redhat linux 6..6 Annam.Venkatesh Linux - Desktop 5 04-20-2016 05:17 PM
CTRL -A representations in Linux terminal log output casperdaghost Linux - Newbie 6 11-09-2011 01:08 PM
Desktop effects gone - "Desktop effects could not be enabled" netjack Ubuntu 3 05-30-2008 09:25 AM
Changing Terminal background colour and font color dpbatagoda Linux - Newbie 0 12-05-2003 12:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration