| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use Gtk2 -init; |
| 4 |
use Gtk2::URxvt; |
| 5 |
use IO::Socket::INET; |
| 6 |
use IO::Pty; |
| 7 |
use Fcntl; |
| 8 |
|
| 9 |
my $peerhost = $ARGV[0] || "towel.blinkenlights.nl"; |
| 10 |
my $peerport = $ARGV[1] || 23; |
| 11 |
|
| 12 |
# allocate/create a new pty |
| 13 |
my $pty = new IO::Pty; |
| 14 |
fcntl $pty, F_SETFD, 0; # clear close-on-exec |
| 15 |
|
| 16 |
# create the window with urxvt |
| 17 |
my $window = new Gtk2::Window 'toplevel'; |
| 18 |
$window->set_default_size (80*9, 25*15); |
| 19 |
my $term = new Gtk2::URxvt args => [-fn => "9x15bold", "-pty-fd" => fileno $pty]; |
| 20 |
$window->add ($term); |
| 21 |
|
| 22 |
$term->realize; # force start of urxvt, so we can close the socket |
| 23 |
close $pty; |
| 24 |
|
| 25 |
my $tty = $pty->slave; |
| 26 |
|
| 27 |
# connect to host |
| 28 |
my $socket = new IO::Socket::INET PeerHost => $peerhost, PeerPort => $peerport |
| 29 |
or die "$peerhost:$peerport: $!"; |
| 30 |
|
| 31 |
# now communicate with rxvt |
| 32 |
add_watch Glib::IO fileno $socket, in => sub { |
| 33 |
sysread $socket, my $buf, 4096 |
| 34 |
or main_quit Gtk2; |
| 35 |
print $tty $buf; |
| 36 |
|
| 37 |
1 |
| 38 |
}; |
| 39 |
|
| 40 |
add_watch Glib::IO fileno $tty, in => sub { |
| 41 |
sysread $tty, my $buf, 128; |
| 42 |
print $socket $buf; |
| 43 |
|
| 44 |
1 |
| 45 |
}; |
| 46 |
|
| 47 |
$window->show_all; |
| 48 |
main Gtk2; |