1796a45b0cbd2113fa33970d48251d9137035672
[profile.git] / .urxvt / font
1 #!/usr/bin/perl
2
3 # Perl extension to resize the terminal.
4 sub on_user_command {
5   my ($self, $cmd) = @_;
6
7   # Get existing fontset, something like:
8   # xft:DejaVu Sans Mono:pixelsize=12:aspect=0.9,xft:AR PL Uming HK
9   my $fontset = $self->{term}->resource("font");
10   my @fonts = split /,/, $fontset;
11   my @new = ();
12
13   # Split into individual font definitions.
14   foreach my $font (@fonts) {
15     if ($font =~ /:pixelsize=(\d+)/) {
16       my $size = $1;
17       my $adjusted = $size;
18
19       # Rewrite the font definition to be resized.
20       if ($cmd =~ /:bigger/) { $adjusted++ }
21       elsif ($cmd =~ /:smaller/) { $adjusted-- }
22
23       $font =~ s/:pixelsize=$size/:pixelsize=$adjusted/;
24     }
25
26     push @new, $font;
27   }
28
29   # Set the new fontset.  Just putting the resource doesn't work so
30   # use an escape sequence.
31   $fontset = join(",", @new);
32   $self->{term}->cmd_parse("\033]50;$fontset\007");
33 }