From 04142a9ec67e9cdaf42d345173d0ffae047e0536 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 27 Aug 2011 01:23:21 -0500 Subject: [PATCH] initial checkin --- README | 0 README.textile | 14 ++++++++++++ font | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) delete mode 100644 README create mode 100644 README.textile create mode 100755 font diff --git a/README b/README deleted file mode 100644 index e69de29..0000000 diff --git a/README.textile b/README.textile new file mode 100644 index 0000000..4a21441 --- /dev/null +++ b/README.textile @@ -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+@ and @Ctrl+Shift+@ 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. diff --git a/font b/font new file mode 100755 index 0000000..b554b42 --- /dev/null +++ b/font @@ -0,0 +1,62 @@ +#!/usr/bin/env perl + +use strict; + +# On-the-fly urxvt font resizing. Like ⌘{+,-}, on mac computers +# +# Noah K. Tilton +# +# 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); } +}