0

I am using a terminal with a white/light background, but output of a command I used contains text with white color (i.e., foreground color = white). Is there any way (e.g., using shell script?) to map all white foreground to black foreground, and keeping the other colors unchanged?

  • Below link will help you to get your question answered how-to-change-the-output-color-of-echo-in-linux – Arulpandiyan Vadivel Apr 19 '17 at 5:38
  • The best would be if you could fix your script not to change the foreground to black or white without changing the background as well - it should change to the default foreground instead. – egmont Apr 19 '17 at 18:17
1
your_script | perl -pe 's/\e\[((?:0;)?)97m/\e[${1}30m/'

Feed your script output to the above given Perl code which transforms all escape color sequences for white foregroud => black fg.

  • More generally colcrt strips display formatting from a text stream. Of course, if the command you already ran cannot easily be run again (because it has external effects which are undesirable, or it takes a long time, etc) this doesn't help at all. – tripleee Apr 19 '17 at 6:56
  • I found a solution on my system (iterm on Mac) based on your solution: your_script | perl -pe 's/\e\[1m/\e[0;30m/g'. Thanks! – AhLeung Apr 25 '17 at 8:13
0

It depends on the terminal. In xterm, you can change the mapping of color numbers to color names with the escape sequence OSC 4 ; NUMBER ; NAME BEL. Explicit white is color 7, so:

printf '\e[4;7;black\a'

This affects the color whether it's used as a background or foreground. It's a rendering setting, i.e. it affects all output past and future.

Few other terminals support this.

0

The precise features of your terminal will differ between versions and implementations. Some traditional terminals offer very little by way of individual window customization, while many desktop OSes have spiffy terminals where you can freely adjust the colors of an individual window by opening the preferences.

As a quick and dirty workaround, selecting the text with the mouse often applies a different color palette which might help. If it doesn't, pasting the text into another window where you have the colors you want is usually a small additional step.

  • 1
    It is possible to remap colors in xterm. There's no GUI for it but there are escape sequences (printf '\e]4;%d;%s' "$color_number" "$color_name_or_hash_rgb"). – Gilles Apr 19 '17 at 22:58
  • @Gilles Thanks! I changed the phrasing somewhat. – tripleee Apr 20 '17 at 3:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.