6

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

echo -e "\033]50;SetProfile=Production\a"

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

echo -e "\033]50;ANY_TEXT\a"

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 "\033c"    # Reset terminal, no effect
    $ echo -e "\033[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

4

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.

  • Using the menu doesn't work; I tried that (it does change the font, but not back to what I had), but using echo -e "\033]50;DejaVu Sans Mono:pixelsize=16\a" resets it! (I did find the list of xterm escape codes, btw, but 50 is written as 5 0, which is why I didn't find it. Do'h!) Thank you. – Martin Tournoij Aug 27 '14 at 8:42
2

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;#0\a

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.
  • Using #n doesn't seem to work, in any case, it's the same as selecting the entry from the menu, which also doesn't work. – Martin Tournoij Aug 27 '14 at 12:04
  • Hmm... for me it worked - but it did not work with the DejaVu example. (There are too many options that could be different...) Th #0 was useful as the menu does not show which font is the default as far as I can see. – Volker Siegel Aug 27 '14 at 12:08
  • You also don't get the original font back by selecting Default on the xterm (assuming you changed it using a font name with the escape sequence; changing to another menu item and then back to default works, of course). At least it didn't in my experiments. – celtschk Aug 30 '14 at 17:07
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.