Escape code 50 in xterm

My coworker has the following in the ~/.bash_profile of many of our servers:

echo -e "33]50;SetProfile=Productiona"

The text doesn’t seem to matter, since this also works:

echo -e "33]50;ANY_TEXTa"

But no text doesn’t work; the a is also required.

This causes his terminal in OSX to change profiles (different colours, etc.); but in my xterm, it changes the font to huge; which I can’t seem to reset.

I have tried to reset this with:

  1. Setting VT fonts with shift+right click
  2. Do “soft reset” and “full reset” with shift+middle click
  3. Sending of various escape codes & commands:

    $ echo -e "33c"    # Reset terminal, no effect
    $ echo -e "33[0;m" # Reset attributes, no effect
    $ tput sgr0          # No effect
    $ tput reset         # No effect
    

My questions:

  1. Why does this work on xterm & what exactly does it do? Code 50 is listed as “Reserved”?
  2. How do I reset this?

Screenshot:

enter image description here

Asked By: Martin Tournoij

||

Looking at the list of xterm escape codes reveals that (esc)]50;name(bel) sets the xterm’s font to the font name, or to an entry in the font menu if the first character of name is a #.

The simplest way to reset it is to use the xterm’s font menu (Ctrl + right mouse click) and select an entry other than Default. Alternatively, you can find out which font the xterm uses on startup, and set that with the escape sequence.

In the font menu you’ll also find an option Allow Font Ops; if you uncheck that, you cannot any more change the font using escape sequences.

Answered By: celtschk

To answer the question of how to reset it:

The xterm escape code OSC 50 ... BEL can be used to set the font (See the answer of @celtschk).

Besides setting it to a font name, it can also be set to an index in the font menu you get with Ctrl and right mouse button.

We can use this to reset to the default font by using the menu index 0:

echo -n "e]50;#0a

From XTerm Control Sequences – (2014/05/26):

OSC P s ; P t BEL  Set Text Parameters.

      P s = 5 0 → Set Font to P t. These controls may be disabled using the
      allowFontOps resource. If P t begins with a "#", index in the font menu,
      relative (if the next character is a plus or minus sign) or absolute. A
      number is expected but not required after the sign (the default is the
      current entry for relative, zero for absolute indexing).
      The same rule (plus or minus sign, optional number) is used when querying
      the font. The remainder of P t is ignored.
      A font can be specified after a "#" index expression, by adding a space
      and then the font specifier.
      If the "TrueType Fonts" menu entry is set (the renderFont resource),
      then this control sets/queries the faceName resource.
Answered By: Volker Siegel

The comment about “reserved” is puzzling because OSC 50 has been documented in xterm’s control sequences since 1991 for changing the font. Here’s a link to the X11R5 version.

The typography in the webpage could be improved. Here’s a quick polish to help you see the problem:

Ps = 5 0 -> Set Font to Pt.

These controls may be disabled
using the allowFontOps resource. If Pt begins with a “#”,
index in the font menu, relative (if the next character is a
plus or minus sign) or absolute. A number is expected but not
required after the sign (the default is the current entry for
relative, zero for absolute indexing).
The same rule (plus or minus sign, optional number) is used
when querying the font. The remainder of Pt is ignored.

A font can be specified after a “#” index expression, by
adding a space and then the font specifier.

If the “TrueType Fonts” menu entry is set (the renderFont
resource), then this control sets/queries the faceName
resource.

Very likely the problem is in the last paragraph, i.e., you were using TrueType fonts and (not just any text) set the font’s facename to a value that did not correspond to a font. Fontconfig has … no useful error checking to speak of … and will simply “recover” by using a default font, not bothering to tell an application that something went wrong. If you did that, you cannot reset via the menu the TrueType fontname (the obvious choices on the fonts menu only change sizes). Control sequences still work, however.

OSX Terminal complements this situation by having no useful documentation. But some of its features are copied from various places (or may be copied to other places). The profile-change feature appeared in KDE Konsole in 2008 as part of the changes for bug report #155801 (curiously citing a rather old copy of xterm’s control sequences document which someone made into a webpage). Actually the 50 was in the code from 2007 (hardcoded). But the change in 2008 gave it a name and commented that it conflicted with xterm’s OSC 50.

Answered By: Thomas Dickey
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.