#!/usr/bin/env perl
#
# changefont - select the next or previous font or change font size in XTerm
#
# usage: changefont +face
# changefont -face
# changefont +size
# changefont -size
#
# $Id: changefont,v 1.5 2022/03/17 19:30:48 schweikh Exp schweikh $
use warnings;
use strict;
use diagnostics;
my $CURRENT_FONT;
my $CURRENT_FACE;
my $CURRENT_SIZE;
$CURRENT_FONT = `xtermcontrol --get-font`;
chop $CURRENT_FONT;
$CURRENT_FONT .= ":size=12" unless $CURRENT_FONT =~ /:/;
($CURRENT_FACE, $CURRENT_SIZE) = split (/:/, $CURRENT_FONT);
$CURRENT_SIZE =~ s/size=//;
push @ARGV, '+face'; # Default: next face.
if ($ARGV[0] eq '+size') {
&setfont ($CURRENT_FACE, $CURRENT_SIZE + 1);
}
elsif ($ARGV[0] eq '-size') {
&setfont ($CURRENT_FACE, $CURRENT_SIZE - 1) unless $CURRENT_SIZE < 7;
}
else {
my @FONT;
my $font = -1;
my $i = 0;
my @mono = split (/\n/, `fc-list :scalable=true:spacing=mono:slant=0: family|sed s:,.\*::|sort -u`);
foreach my $face (sort @mono) {
next if $face =~ /(Cursor|dings$|Untitled|^Marlett|^Scratch|Bold|Italic|Obl|^Courier$)/;
push @FONT, $face;
$font = $i if $face eq $CURRENT_FACE;
++$i;
}
if ($font == -1) {
$font = 0;
}
elsif ($ARGV[0] eq '+face') {
$font = ($font + 1) % ($#FONT + 1);
}
elsif ($ARGV[0] eq '-face') {
$font = ($font + $#FONT) % ($#FONT + 1);
}
&setfont ($FONT[$font], $CURRENT_SIZE);
}
sub setfont {
my ($face, $size) = @_;
print "$face:size=$size\n";
system 'xtermcontrol', '--font', $face . ":size=" . $size;
}
# vi: set syntax=perl tabstop=4 shiftwidth=4 expandtab
So you can always ctrl-right click and choose a smaller or larger font from the dropdown menu...
Speaking of that, how do I configure which fonts and sizes show up in that menu?
! VT Font Menu: Unreadable
xterm*faceSize1: 8
! VT font menu: Tiny
xterm*faceSize2: 10
! VT font menu: Medium
xterm*faceSize3: 12
! VT font menu: Large
xterm*faceSize4: 16
! VT font menu: Huge
xterm*faceSize5: 22
xterm*vt100.Translations: #override \
Meta <Key>C: copy-selection(PRIMARY) \n\
Ctrl <Key>V: insert-selection(PRIMARY) \n\
Meta <Key>V: insert-selection(PRIMARY) \n\
Ctrl <Key> minus: smaller-vt-font() \n\
Meta <Key> minus: smaller-vt-font() \n\
Ctrl <Key> plus: larger-vt-font() \n\
Meta <Key> plus: larger-vt-font() \n\
Ctrl <Key> KP_Subtract: smaller-vt-font() \n\
Meta <Key> KP_Subtract: smaller-vt-font() \n\
Ctrl <Key> KP_Add: larger-vt-font() \n\
Meta <Key> KP_Add: larger-vt-font()
Thank you so much! I have been wondering for years.Code:! VT Font Menu: Unreadable xterm*faceSize1: 8 ! VT font menu: Tiny xterm*faceSize2: 10 ! VT font menu: Medium xterm*faceSize3: 12 ! VT font menu: Large xterm*faceSize4: 16 ! VT font menu: Huge xterm*faceSize5: 22 xterm*vt100.Translations: #override \ Meta <Key>C: copy-selection(PRIMARY) \n\ Ctrl <Key>V: insert-selection(PRIMARY) \n\ Meta <Key>V: insert-selection(PRIMARY) \n\ Ctrl <Key> minus: smaller-vt-font() \n\ Meta <Key> minus: smaller-vt-font() \n\ Ctrl <Key> plus: larger-vt-font() \n\ Meta <Key> plus: larger-vt-font() \n\ Ctrl <Key> KP_Subtract: smaller-vt-font() \n\ Meta <Key> KP_Subtract: smaller-vt-font() \n\ Ctrl <Key> KP_Add: larger-vt-font() \n\ Meta <Key> KP_Add: larger-vt-font()
I learned this from: https://vermaden.wordpress.com/2021...-part-25-configuration-random-terminal-theme/
It depends if you're putting the values in the .Xresources/.Xdefaults file or in the app-defaults file whose name is XTerm (it used to be in /usr/share/X11/app-defaults/XTerm, but different implementations put it in different places, the manpage should tell you where). In the app-defaults file you use XTerm with the first two letters capitalised. Which I always thought is a pretty hokey old interface, Jim Gettys and Rob Scheiffler. I think it's something to do with being a class name or an instance name, but I can't remember without going and looking it upSometimes the Xresources are named "XTerm*" not just "xterm*"