2

From fbterm(1) we can read:

FbTerm supports xterm's 256 color mode extension.  (...)  But xterm's 256 color escape sequences conflict with the linux sequences implemented by FbTerm, so private escape sequences were introduced to support this feature:

   ESC [ 1 ; n }                   set foreground color to n (0 - 255)
   ESC [ 2 ; n }                   set background color to n (0 - 255)
   ESC [ 3 ; n ; r ; g ; b }       set color n to (r, g, b) , n, r, g, b all in (0 - 255)

How can these escape sequences be written with the command echo -ne?

merryup
  • 21
  • 3

1 Answers1

2

You can use e.g.

echo -ne "\E[2;32} "

which should print a blue space. (32 is the 32nd colour in the default 8-bit colour table which seems to be blue.)

(Of course you can also use \x1b or \033 instead of \E to represent the escape character.)

To view all 255 colours you can use for i in {0..255}; do echo -ne "\E[2;$i} "; done; tput sgr0; echo or for i in {0..255}; do echo -ne "\E[2;$i}$i "; done; tput sgr0; echo which also includes the number of the colour.

Example: colour output example captured with fbgrab from framebufferconsole

Kai
  • 33
  • 3
  • Do you have a reference for the default colour palette? – Attie Oct 06 '18 at 22:52
  • No, but you could try something like `for i in {0..255}; do echo -ne "\E[2;$i} "; done; tput sgr0; echo`, this should print 255 coloured spaces and reset every text-colour-related setting to defaults in the end (`tput sgr0`). – Kai Oct 09 '18 at 05:31
  • Indeed - perhaps you could add this to your answer with a screenshot of the result? Numbers in the color would be even better :-) – Attie Oct 09 '18 at 09:21
  • 1
    Done, I added both one-liners (-: – Kai Oct 10 '18 at 07:38
  • How do you end the color without `tput sgr0` ? What is the escape sequence? – Gringo Suave Sep 14 '19 at 21:22
  • @GringoSuave apparently it's possible to use `echo -ne "\E[0;0m"` (see e.g. https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797#8-16-colors) – Kai Jul 22 '21 at 13:19
  • Ok, that is the standard one. – Gringo Suave Jul 27 '21 at 03:57