Terminal Brightness – Can’t Apply Brightness to Terminal’s Background Color

bashterminalterminal-emulator

I have a problem with colors in my terminal emulator. I am using LXTerminal as my terminal emulator and LXDE as my desktop environment.

The following command is supposed to print red text on grey background:

printf "\n\033[1;31;40m"hello"\033[00m\n\n"

but that does not work. The grey background is missing (red text is OK). On my older machine (Gnome/Gnome Terminal) everything works fine

I have tried installing several other terminal emulators, but the problem persists. I am not even sure whether this issue is related to terminal emulator, or something else. In Console (CTRL+ALT+F1) the background grey color does not work on either machine)

This problem is limited to grey background only. All other colors work OK, for instance the following prints red text on green background.

printf "\n\033[1;31;42m"hello"\033[00m\n\n"

I would appreciate any help. I don't even know where to start troubleshooting.

Best Answer

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 
Related Question