From 80b89311396fadef538b8e43b42c42f07a3a62c7 Mon Sep 17 00:00:00 2001 From: Jason May Date: Thu, 10 Mar 2011 11:56:04 -0500 Subject: send new term geometry when the window changes --- dist.ini | 1 + lib/App/Termcast.pm | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dist.ini b/dist.ini index 8fb6c81..f01d276 100644 --- a/dist.ini +++ b/dist.ini @@ -12,3 +12,4 @@ IO::Pty::Easy = 0.07 Term::ReadKey = 0 MooseX::Getopt = 0 Scope::Guard = 0 +JSON = 0 diff --git a/lib/App/Termcast.pm b/lib/App/Termcast.pm index 9ac3a8d..fe88c3f 100644 --- a/lib/App/Termcast.pm +++ b/lib/App/Termcast.pm @@ -8,6 +8,7 @@ use IO::Pty::Easy; use IO::Socket::INET; use Scope::Guard; use Term::ReadKey; +use JSON; =head1 SYNOPSIS @@ -136,6 +137,15 @@ has socket => ( init_arg => undef, ); +sub _form_metadata_string { + my $self = shift; + my %data = @_; + + my $json = JSON::encode_json(\%data); + + return "\e[H\x00$json\xff\e[H\e[2J"; +} + sub _build_socket { my $self = shift; @@ -152,8 +162,17 @@ sub _build_socket { my ($cols, $lines) = GetTerminalSize(); + my $resize_string = $self->_form_metadata_string( + geometry => [ $cols, $lines ], + ); + $socket->syswrite($self->establishment_message); - $socket->syswrite("geom $cols $lines\nfinish\n\e[H\e[2J"); + select undef, undef, undef, 0.1; # XXX yuck :) + # this is going away once I move + # auth to on_data in ::Server + # instead of on_connect or whatever + # - jasonmay + $socket->syswrite($resize_string); # ensure the server accepted our connection info # can't use _build_select_args, since that would cause recursion @@ -307,7 +326,18 @@ sub run { local $SIG{WINCH} = sub { $self->_got_winch(1); $self->pty->slave->clone_winsize_from(\*STDIN); + $self->pty->kill('WINCH', 1); + + syswrite STDOUT, "\e[H\e[2J"; # for the sake of sending a + # clear to the client anyway + + my ($cols, $lines) = GetTerminalSize(); + my $resize_string = $self->_form_metadata_string( + geometry => [$cols, $lines], + ); + + syswrite $self->socket, $resize_string; }; while (1) { -- cgit v1.2.3-54-g00ecf