urxvt: on-the-fly font changing

Deep in the mists of time, rxvt had "use smaller font" and "use bigger font" keystrokes. Now, instead of that facility, it has escape codes to set the font. It's possible to bind these to keys, as documented in urxvt(1) under CHANGING FONTS. But it's also possible to do it from a program. These are non-standard codes ESC ] 710 ... \007 and ESC ] 711 ... \007 which are further documented in urxvt(7), which calls them "XTerm Operating System Commands", so in fact some versions of xterm might support the feature as well.

Furthermore, screen provides a way to write directly to the terminal, bypassing screen's own escape-code handling. This is ESC P ... ESC \.

Taken together, this makes it possible to programmatically change the font in a urxvt by running a program in the shell, even if the shell is running inside screen. The "sleep" is so that this can be run by '<screen key>: screen ufn 1'. If the given screen is not active at the time, the sequence inside ESC P ... ESC \ is not actually passed through to the terminal.

The attached program, ufn, does just that. With no arguments or with the argument "1", it switches to my usual font. With arguments "2" and "3" it switches to two other ugly fonts. Or you can give an arbitrary font argument.

Files currently attached to this page:

ufn300 bytes



Entry first conceived on 8 February 2011, 14:01 UTC, last modified on 15 January 2012, 3:46 UTC
Website Copyright © 2004-2024 Jeff Epler