Index: lang/perl/Net-Partty/trunk/example/pertty.pl
===================================================================
--- lang/perl/Net-Partty/trunk/example/pertty.pl (revision 8442)
+++ lang/perl/Net-Partty/trunk/example/pertty.pl (revision 8449)
@@ -23,4 +23,5 @@
     '--readonly_password=s' => \$opts->{readonly_password},
     '--kill_guest'          => \$opts->{kill_guest},
+    '--noconnect'           => \$opts->{noconnect},
 ) or pod2usage(2);
 Getopt::Long::Configure("bundling");
@@ -34,7 +35,10 @@
 use YAML;warn Dump($opts);
 
-my $partty = Net::Partty->new;
-eval { $partty->connect(%{ $opts }) };
-pod2usage(-verbose => 2) if $@;
+my $partty;
+unless ($opts->{noconnect}) {
+    $partty = Net::Partty->new;
+    eval { $partty->connect(%{ $opts }) };
+    pod2usage(-verbose => 2) if $@;
+}
 $ENV{PARTTY_SESSION} = $opts->{session_name};
 
@@ -75,13 +79,15 @@
 
 ReadMode 'raw', \*STDIN;
+set_windowsize(\*STDOUT, $master);
+
 $master->blocking(0);
 STDIN->blocking(0);
 STDOUT->blocking(0);
-$partty->sock->blocking(0);
+$partty->sock->blocking(0) unless $opts->{noconnect};
 
 my $select = IO::Select->new;
 $select->add($master);
 $select->add(\*STDIN);
-$select->add($partty->sock);
+$select->add($partty->sock) unless $opts->{noconnect};
 
 my $m_fno = fileno($master);
@@ -89,7 +95,11 @@
 my $p_fno = fileno($partty->sock);
 
+my $out_select = IO::Select->new;
+$out_select->add(\*STDOUT);
+
 while (1) {
     my @ready = $select->can_read(10);
     next unless @ready;
+    set_windowsize(\*STDOUT, $master);
     for my $fh (@ready) {
         my $fno = fileno($fh);
@@ -97,6 +107,9 @@
             my $len = $fh->sysread(my $buf, 4096);
             STDOUT->syswrite($buf, $len);
-            $partty->can_write(100);
-            $partty->sock->syswrite($buf, $len);
+            unless ($opts->{noconnect}) {
+                $partty->sock->syswrite($buf, $len);
+                $partty->can_write(100);
+            }
+            $out_select->can_write(100);
         } elsif ($fno == $i_fno) {
             my $len = $fh->sysread(my $buf, 4096);
@@ -109,4 +122,20 @@
 }
 print "end\n";
+
+my $old_size;
+sub set_windowsize {
+    my($in, $out) = @_;
+
+    my @size = GetTerminalSize $in;
+    my $now_size = join '-', @size;
+    return if $now_size eq $old_size;
+    $old_size = $now_size;
+    SetTerminalSize @size, $out;
+
+    return if $opts->{noconnect};
+    my $cmd = pack 'CCCnnCC', 255, 250, 31, $size[0], $size[1], 255, 240;
+    $partty->sock->syswrite($cmd, 9);
+    $partty->can_write(100);
+}
 
 __END__
@@ -124,4 +153,5 @@
         -r <view password>       password to view the session
         -k                       disable all gust operation regardless of operation password
+        -n                       not connect to partty server
 
 =head1 UNSUPPORTED
@@ -131,4 +161,4 @@
 =head1 TODO
 
-    terminal size を継承する
-    
+    terminal size を継承する(もう少しちゃんと)
+    Ctlr-C とかが効かないので何とかする
