Font resizing (was Re: Font spacing)
John Eikenberry
jae at zhar.net
Wed Dec 31 04:32:33 CET 2008
Bob Hepple wrote:
> BTW - The added bonus with mrxvt is that Shift-KP_ADD and
> Shift-KP_Subtract allow the font to be tweaked up and down in size -
Attached is a Perl script to add the same functionality to urxvt. The fonts
are hard-coded in the script, and it probably isn't the best Perl as I
don't normally use Perl. But here it is for what it's worth.
--
John Eikenberry
[jae at zhar.net - http://zhar.net]
[PGP public key @ http://zhar.net/jae_at_zhar_net.gpg]
______________________________________________________________
"Perfection is attained, not when no more can be added, but when no more can be
removed." -- Antoine de Saint-Exupery
-------------- next part --------------
# Cycle through set of font sizes
# by John Eikenberry <jae at zhar.net>
#
# called via keysym hook in .Xresources
# E.g., To use Ctrl-Meta-[plus]/Ctrl-Meta-[minus] use...
# URxvt*keysym.C-M-equal: command:\033]777;font-size:+\007
# URxvt*keysym.C-M-minus: command:\033]777;font-size:-\007
#
# Be warned. I don't use perl normally. So this might not be optimal.
use strict;
use List::Util qw(first);
# font and sizes that I can cycle to
my $font_name = 'terminus';
my @font_sizes = qw(12 14 16 20 24 28 32);
my @fonts = map{"$font_name-$_"} @font_sizes;
# same as the URxvt*font line in my .XResources file
my $font_default = 'terminus-16, -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1';
# urxvt hook
sub on_osc_seq_perl {
# $self is terminal object reference
# $str is string after escape sequence
my ($self, $str) = @_;
# current font size of terminal
my $sz = $self->{term}->resource('font');
$sz =~ s/$font_name-(\d+).*/$1/;
# loop through font sizes and set new size
# should probably use a map instead, but this works
my $max = (scalar @font_sizes) - 1;
my $font = $font_default;
foreach (0 .. $max) {
if ($font_sizes[$_] == $sz) {
if ($str =~ /font-size:\+/) {
my $idx = $_ + 1;
# stop at max size
if ($idx >= $max) { return };
$font = $fonts[$idx];
last;
} else {
my $idx = $_ - 1;
# stop at min size
if ($idx < 0) { return };
$font = $fonts[$idx];
last;
};
};
};
# set new font on terminal
$self->{term}->cmd_parse("\033]50;$font\007");
};
## vim: ft=perl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.schmorp.de/pipermail/rxvt-unicode/attachments/20081230/71f2a9dc/attachment.pgp>
More information about the rxvt-unicode
mailing list