forked from xyb3rt/urxvt-perls
-
Notifications
You must be signed in to change notification settings - Fork 2
/
resize-font
65 lines (57 loc) · 2.02 KB
/
resize-font
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# vim:ft=perl:fenc=utf-8
# Copyright (c) 2009-, Simon Lundström <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# Usage:
# Set your font in ~/.Xresources:
# urxvt.font: xft:Inconsolata:pixelsize=12
# And re-bind some keymappings (if you want, below are the defaults):
# URxvt.resize-font.smaller: C-minus
# URxvt.resize-font.bigger: C-plus
# URxvt.resize-font.reset: C-equal
# URxvt.resize-font.show: C-question
#
my $default_font;
sub on_start {
$default_font = $_[0]->resource('font');
}
sub on_user_command {
my ($self, $string) = @_;
if ($string =~ /resize-font:/) {
my $font = $self->resource('font');
my $regex = qr"(?!size=)(\d+)";
if ($string =~ /resize-font:bigger$/) {
$font =~ s/$regex/$1+1/e;
}
elsif ($string =~ /resize-font:smaller$/) {
$font =~ s/$regex/$1-1/e;
}
elsif ($string =~ /resize-font:reset$/) {
$font = $default_font;
}
elsif ($string =~ /resize-font:show$/) {
my $term = $self->{'term'};
$term->{'resize-font'}{'overlay'} = {
ov => $term->overlay_simple (0, -1, $font),
to => urxvt::timer
->new
->start (urxvt::NOW + 1)
->cb(sub {
delete $term->{'resize-font'}{'overlay'};
}),
};
}
$self->cmd_parse(sprintf "\033]710;%s\007", $font);
}
()
}