It almost seems like overstriking
That's exactly what it is. As at https://superuser.com/a/711019/38062 it helps to think of the action of mechanical typewriters when it comes to Unix terminals. In this case, the sequence
_ BS (the backspace character) before a character is a convention that is used to indicate underlining of that character, because on some terminals that's how one underlined text. An alternative control sequence is BS
_ after the character. On the original terminals it didn't matter what overstruck what, of course.
ncal, which is what this program is, has two modes of operation when it comes to highlighting.
- If its output is a terminal, it looks up the
se sequences for the current terminal type in the termcap database and emits those either side of the highlighted text. (There's actually a bug in the code that does this, to do with a buffer on the stack going out of scope and its contents being used later, that no-one seems to have spotted.)
- If its output is not a terminal, it emits the text with each character to be highlighted preceded by a
_ BS sequence.
You cannot replicate this by emitting a
_ BS sequence to your terminal, unless (of course) your terminal is one of the terminals where this is how one underlines stuff. This isn't the case for terminal emulators, and almost certainly isn't the case for whatever terminal(s) or terminal emulator(s) you are using here.
You can however filter text that uses this convention, through the
ul program, which recognizes this and several other typewriter-like conventions and translates them to whatever the control sequences for one's terminal actually are, looking them up in the termcap database. You can filter the outputs of your
printf commands through
On other terminals I tried it just underlines it.
Ironically, filtering the non-terminal-mode output of
ncal through the
ul program is in fact slightly superior to letting
ncal write terminal control sequences itself. Whereas
ncal uses the terminal's standout mode,
ul will attempt to use the terminal's actual underline mode (if it has one) when translating the
_ BS sequence. As the termcap manual explains, standout mode can be whatever is suitable to the terminal (including boldface, reverse video, or colours) and isn't necessarily underlining. On one of your terminals it is clearly a combination of underlining and a colour change.
ul also copes with terminals that don't have underline start/end sequences but that do have underline last character sequences. Ironically,
ul will cope if your terminal really is one that underlines by having BS
_ after each character, whereas
ncal will not cope.
And of course
ul doesn't have
ncal's buffer handling bug. ☺
If I pipe the output into
less -R, it changes its color to yellow and underlines it.
As you've spotted, the
less program understands
_ BS sequences and handles them somewhat as the
ul program does. It's not completely the same.
ul can handle sequences involving multiple
_ and BS characters, and can also handle similar sequences for boldface.
less cannot. Contrast what you see from these two:
back in the good old days
Sadly, these still are "the good old days". Don't let people fool you into believing that this is rarely used nowadays.
It's not in the manual, but the source code for
ul points out that it is attempting to implement the control sequence processing of a Teletype Model 37 because "that's what
nroff outputs". The GNU replacement for the original Unix
nroff program, written long after terminals had gained fancy features like colours, boldface, and italics, is capable of generating ECMA-48 control sequences for colours, boldface, and italics. It actually does so in the normal case.
nroff, and its GNU replacement, are used for formatting manual pages for display on your terminal. Sadly, and ironically, starting about 10 years after it was written people proceeded to hobble the GNU tool so that it generated the old Teletype Model 37 sequences from 1968 instead of the "new" ECMA-48 control sequences from 1976 (sic!). They made
groff with options that modified its default behaviour, and added undocumented files that forced extra ditroff output.
Every time that you read a manual page on your terminal, the manual system is running
groff which is dutifully converting the manual source text into an output character stream with these old Teletype Model 37 control sequences, which
more are converting into your terminal's control sequences.