summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason May <jason.a.may@gmail.com>2011-03-10 11:56:04 -0500
committerJesse Luehrs <doy@tozt.net>2011-04-14 01:19:03 -0500
commit80b89311396fadef538b8e43b42c42f07a3a62c7 (patch)
treef0a24942c0ef4c2ffa1e394201140f3ea4200337
parente5df37703cab30b37a4ff5ed177db7b12104390d (diff)
downloadapp-termcast-80b89311396fadef538b8e43b42c42f07a3a62c7.tar.gz
app-termcast-80b89311396fadef538b8e43b42c42f07a3a62c7.zip
send new term geometry when the window changes
-rw-r--r--dist.ini1
-rw-r--r--lib/App/Termcast.pm32
2 files changed, 32 insertions, 1 deletions
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) {