You can have a look into TERM
settings. It is possible it is set to lesser then capable string. To test colors you can run GNU's msgcat
. Try e.g.:
echo $TERM
msgcat --color=test
TERM=xterm-256color
msgcat --color=test
Or use @Ignacio Vazquez-Abrams's loop instead of msgcat.
For more information on how and what to set have a look at e.g.:
There are eight standard ANSI colors, supported by every terminal emulator. Most terminal emulators also have eight bright variants of the standard ANSI colors.
However, the actual color values that the escape codes map to aren't standardized, and in fact they often slightly vary among terminal emulators. So if you do printf "\e[31;47mTest\n"
to print red text on a white background, the actual hues of red and white you get may be different depending on the terminal emulator you use.
So that partly explains the problem: color values aren't standard, and LXTerminal
may have different defaults for its color palette that you're not used to. If you look around in the settings, usually you can configure the color scheme to be whatever you like.
The other problem you face is that what the bold attribute actually does isn't standardized either. There are three possibilities: it can make the font bold, it can make the foreground color brighter, or it can both make the foreground color brighter and make the font bold.
Again, the default behavior here varies among terminal emulators, and you can usually change it if can you find the right setting. Grep for something mentioning 'bold' or 'bright'.
If you want to use a bright color, then you can use the so-called aixterm color escape codes instead of bold. These aren't standard, but they're supported in every modern terminal emulator I know of. Unlike bold, they always use bright colors, plus they can be used to display bright background colors.
So for example, if you wanted to print bright red text on a bright white background, you would do this: printf "\e[91;107mTest\n"
.
For reference, here's a table of all the color escape codes:
| ANSI | ANSI | ANSI | | Aixterm | Aixterm
| Color | FG Code | BG Code | Bright Color | FG Code | BG Code
+---------+---------+-------- +----------------+---------+--------
| Black | 30 | 40 | Bright Black | 90 | 100
| Red | 31 | 41 | Bright Red | 91 | 101
| Green | 32 | 42 | Bright Green | 92 | 102
| Yellow | 33 | 43 | Bright Yellow | 93 | 103
| Blue | 34 | 44 | Bright Blue | 94 | 104
| Magenta | 35 | 45 | Bright Magenta | 95 | 105
| Cyan | 36 | 46 | Bright Cyan | 96 | 106
| White | 37 | 47 | Bright White | 97 | 107
Best Answer
In
zsh
, you don't need to hardcode escape sequences as it has several builtin ways to set the background and foreground colours.You can use
echoti setaf
toset
the terminala
nsif
oreground colour andechoti setab
to set theb
ackground one (setaf
andsetab
being the names of the correspondingt
ermi
nfo capabilities)Assuming your terminal supports 256 colours (as VTE-based ones such as your gnome-terminator do) and
$TERM
is correctly set to a value that identifies a terminfo entry with the right escape sequences for that, it should work.Or you can use prompt expansion with
print -P
or the%
parameter expansion flag and:(here
sed -n l
is used to reveal the corresponding escape sequence that is being sent,$
is just to show where the line ends, it's not part of the output,\033
is GNUsed
'sl
command's representation of the ESC character (with octal 033 byte value in ASCII))Some terminals (including VTE-based ones such as your gnome-terminator) also support RGB specifications. On those, you could do
(here with
fffffff
for bright white as that'sff
the maximum value for all of the red, green and blue components). In that case,zsh
hardcodes the xterm-style sequence (see there for the background) as there is no corresponding terminfo capability. Though not standard, that's currently the most widely supported across modern FLOSS terminal emulators.%K
sets the background colour,%F
for foreground.%k
/%f
restore the default colour.For terminals that don't support that but do support the 88 or 256 colour palette,
zsh
also has azsh/nearcolor
module to get you the colour nearest to that RGB specification:(here colour 231 on my 256 colour terminal is the closest one to bright white, it is actually bright white).
If you have access to the X11
rgb.txt
file, you could also define associative arrays for each of the X11 colour names with something like:(Debian-like systems have
/etc/X11/rgb.txt
as part of thex11-common
package).To do things like:
For more details, see:
man 5 terminfo
info zsh echoti
info zsh print
info zsh "Prompt Expansion"
info zsh "The zsh/nearcolor Module"
(beware that on some systems, you need to install a
zsh-doc
package or equivalent for theinfo
pages to become available).