From 3737f9223a7ef620ae95e614e35cb4b50c094125 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 14 Apr 2011 01:43:13 -0500 Subject: factor this out into a method --- lib/App/Termcast.pm | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/App/Termcast.pm b/lib/App/Termcast.pm index d8ecb36..ed7d561 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 Try::Tiny; use JSON; =head1 SYNOPSIS @@ -129,6 +130,18 @@ sub _build_establishment_message { return sprintf("hello %s %s\n", $self->user, $self->password); } +sub termsize_message { + my $self = shift; + + my ($cols, $lines) = try { GetTerminalSize() }; + + return '' unless $cols && $lines; + + return $self->_form_metadata_string( + geometry => [ $cols, $lines ], + ); +} + has socket => ( traits => ['NoGetopt'], is => 'rw', @@ -160,13 +173,7 @@ sub _build_socket { } } - my ($cols, $lines) = GetTerminalSize(); - - my $resize_string = $self->_form_metadata_string( - geometry => [ $cols, $lines ], - ); - - $socket->syswrite($self->establishment_message . $resize_string); + $socket->syswrite($self->establishment_message . $self->termsize_message); # ensure the server accepted our connection info # can't use _build_select_args, since that would cause recursion -- cgit v1.2.3-54-g00ecf