1
0
mirror of https://github.com/gryf/urxvt-font.git synced 2026-03-18 22:13:33 +01:00

initial checkin

This commit is contained in:
noah
2011-08-27 01:23:21 -05:00
parent 9e887b57c6
commit 04142a9ec6
3 changed files with 76 additions and 0 deletions

0
README
View File

14
README.textile Normal file
View File

@@ -0,0 +1,14 @@
h2. About
urxvt is a great terminal emulator, but spending time on a mac made me miss the
ability (in iTerm!) to dynamically resize text using ⌘+Plus and ⌘+Minus. I was
also thinking that it would be be nice if resizing the terminal font could be
persisted to @Xresources@. Turns out this was pretty easy to accomplish.
bc.
urxvt.perl-lib: /path/to/urxvt-font
urxvt.keysym.Control-Shift-Up: perl:font:increment
urxvt.keysym.Control-Shift-Down: perl:font:decrement
urxvt.perl-ext-common: font
Now, @Ctrl+Shift+<Up>@ and @Ctrl+Shift+<Down>@ will, respectively, enlarge and decrease the text size in a running urxvt window, *and* save the new font size to @~/.Xresources@, so that it's there for the next time you open a terminal window. With the Monaco font, it's a poor man's iTerm.

62
font Executable file
View File

@@ -0,0 +1,62 @@
#!/usr/bin/env perl
use strict;
# On-the-fly urxvt font resizing. Like ⌘{+,-}, on mac computers
#
# Noah K. Tilton <noahktilton@gmail.com>
#
# What it does:
#
# 1) Emits escape sequences to change the font size in the running console;
# 2) Persists the changed font size to xresources file.
#
# Note: the regexes will only work on xft xrdb entries
#
# References: man 3 urxvtperl
use constant X_RESOURCES => "~/.Xresources";
sub change_size
{
my ($self, $cmd) = @_;
my (@pieces) = split /:/, $self->{term}->resource("font"); # TODO make boldFont work
my (@resized) = ();
foreach my $piece (@pieces)
{
if ($piece =~ /pixelsize=(\d*)/)
{
my $size = $1;
my $new_size = (($cmd =~ m/font:increment/) ? ($size+1) : ($size-1));
$piece =~ s/pixelsize=$size/pixelsize=$new_size/;
}
push @resized, $piece;
}
my ($resized_str) = join (":", @resized);
my $UPDATE_STR = "urxvt\*" . $case . ":" . $resized_str . "\n";
my $SAVE_STR = "xrdb -edit " . X_RESOURCES;
my $RESIZE_STR = "\033]50;" . $resized_str . "\007";
my $LOAD_STR = "xrdb -load " . X_RESOURCES;
system($LOAD_STR); # load the xrdb db
open(XRDB_MERGE, "| xrdb -merge") || die "can't fork: $!";
local $SIG{PIPE} = sub { die "xrdb pipe broke" };
print XRDB_MERGE $UPDATE_STR; # merge the new values
close XRDB_MERGE || die "bad xrdb: $! $?";
system($SAVE_STR); # write the db values back to the file
$self->{term}->cmd_parse($RESIZE_STR); # update the urxvt runtime
}
sub on_user_command
{
# This function is called whenever some urxvt.keysym.*: perl:x:y
# mapped in X_RESOURCES is called; where x is this "module" (file,
# translation unit...), y is some function in this file (and this
# function, if defined), and $cmd is the argument z.
#
my ($self, $cmd) = @_;
if ($cmd =~ /font:..crement/) { $self->change_size($cmd); }
}