Solved Colors in the FreeBSD terminal

Hello. Using the following snippet of Shell code script, I've been able to determine that my terminal on FreeBSD does support 256 colors.

Code:
for COLOR in {0..255}
do
    for STYLE in "38;5"
    do
        TAG="\033[${STYLE};${COLOR}m"
        STR="${STYLE};${COLOR}"
        echo -ne "${TAG}${STR}${NONE}  "
    done
    echo
done

The code is from this Stack Overflow article https://stackoverflow.com/questions/6159856/how-do-zsh-ansi-colour-codes-work

This gives me colors such as...

Screen Shot 2018-03-24 at 03.58.18.png


I'm using zsh for my shell. My question is how do I use any color in the zsh prompt. At the moment my prompt command is
PROMPT='%F{magenta}%n%f@%F{cyan}%m%f %F{yellow}%1~%f %# '

I've read this old post https://forums.freebsd.org/threads/set-terminal-to-256-colors.8450/ but my terminal program doesn't appear to have the facility to edit-->preferences-->advanced-->$TERM settings, as that post would suggest. If the terminal can physically display the colors, surely there's a way of persuading zsh to look beyond the standard 8 colors for prompt purposes.

I've looked in the handbook but that only seems to consider the existence of 8 colors, unless I've missed something.

Can any suggest how to do this?
 
...the handbook but that only seems to consider the existence of 8 colors...
The handbook sections you read probably are talking about the text console, which is limited to 8 colors (and a background bit, resulting in 16 colors) by hardware.
Just use the color escapes instead of the hardcoded color names.
 
It turned out to be much easier than I was making it. Simply replacing the named color with the last numeric code does the trick.

So, for instance, replacing the colors in PROMPT='%F{magenta}%n%f@%F{cyan}%m%f %F{yellow}%1~%f %# ' with their hi-intensity equivalents can be done by
PROMPT='%F{13}%n%f@%F{14}%m%f %F{11}%1~%f %# '

I wonder if there is a way to get named colors beyond the basic 8. I will investigate...
 
Back
Top