6

Output from the man command has bold and underlined text that can be read by less.

For example, H\x08HE\x08EL\x08LL\x08LO\x08O displays HELLO (boldface) or H\x08_E\x08_L\x08_L\x08_O\x08_ displays HELLO with an underline.

What is this kind of formatting called?

2 Answers 2

11

The method is called overstriking or overtyping, and goes back to the days of typewriters.

Byte 0x08 (aka \x08 or ^H) is the ASCII "Backspace" character. With typewriters and line-printers, it would move the cursor back one character, so the following character would be printed on paper at the same position as last one. Most commonly, either a character is overstruck over itself (resulting in bold text), or over an underscore _ (resulting in underlined text).

Computer terminals normally also delete the backspaced-over character, so this method would no longer work. However, many pagers such as less (the default pager used by man) or w3m automatically translate the two cases mentioned above into actual bold/underline formatting.

(See also ASA carriage control characters used by mainframes and line printers; they have an "overstrike last line" option instead of using Backspace.)

Compare this to combining characters found in Unicode.

1
  • 2
    Note that \b on a terminal doesn't delete the character, it's just that in H\b_, _ replaces the H (it's _ that deletes H, not \b). Also note that there are Unicode underlining combining characters nowadays so another way to write an underlined H is to write a H followed by U+0332 like . (which my firefox doesn't render properly btw). Mar 8, 2014 at 18:54
2

That's plain ASCII, nothing special about it. The \x08 is ASCII code for backspace so the first one does H-backspace-HE-backspace-E... (writes every character twice) and the second does H-backspace-_ and so on. It's what you would do on a typewriter to get bold and underline.

On the other hand, to handle color, you output ASCII escape codes that are interpreted by the virtual terminal to show color, blink, position cursor and so on. It's how commands like ls write in color:

http://en.wikipedia.org/wiki/ANSI_escape_sequences

To allow less to preserve the ASCII escape codes, you call it as less -R. For instance, this command displays ls output in color in less:

/bin/ls --color -B -F -1 | less -R

Which I have as alias to lsl.

5
  • But this backspace and next character need to be processed by terminal, it need to be called somehow.
    – jcubic
    Mar 8, 2014 at 10:42
  • 1
    @jcubic: Not everything in the world has a name. It might easily have been "that odd thing some terminals do". Mar 8, 2014 at 10:42
  • Well terminals speak ASCII, that's actually the reason ASCII was invented. First 32 codes in ASCII are typewriter stuff like "tab", "carriage return", "line feed", "delete", "vertical tab" and so on, together with old-school remote terminal stuff to handle communication (start/end block, start/end stream,...). So your terminal is processing it all the time - newlines are done this way as well.
    – orion
    Mar 8, 2014 at 10:44
  • most terminals speak ANSI they display colors and stuff, so I thought that this have a name from some old terminal type.
    – jcubic
    Mar 8, 2014 at 10:49
  • Just to paraphrase what grawity said: ASCII escape codes also handle bold, underline, inverted (selected), background color and so on, so these "overstrike" options that would only work on real printer, are converted into escape codes by less.
    – orion
    Mar 8, 2014 at 11:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .