views:

76

answers:

2

Using terminal sequences, I can colour text in a terminal emulator:

$ echo -e '\e[37;41m--this is white on red--\e[0m'

And this works.

The following prints a red rectangle, i.e. space characters have a red background and an empty foreground:

$ echo -e '\e[37;41m     \e[0m '

But the following prints two red rectangles separated by a tab:

$ echo -e '\e[37;41m  \t  \e[0m '

That is, the tab character does not receive the red background highlighting. It takes the default terminal background colour.

Why isn't tab highlighted like space? Can I force this some other way?

+2  A: 

If you don't need the tabs to be tabs, you could preprocess your text through expand(1).

ankon
That's a good suggestion, and chances are I will end up doing something like that.
sjbach
+2  A: 

I've found the answer: no, tab cannot be highlighted in a standards compliant terminal emulator. Tab is not really whitespace in the terminal; it is explicitly a cursor movement character to go forward to the next tab stop. So, in effect my example says "print two spaces on red background, move forward to the next tab stop, then print two more spaces on red background".

The workaround would be ankon's suggestion to convert tabs to spaces before printing.

sjbach