summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-04-14 01:43:13 -0500
committerJesse Luehrs <doy@tozt.net>2011-04-14 01:43:13 -0500
commit3737f9223a7ef620ae95e614e35cb4b50c094125 (patch)
treee9240a6e5ca46294667faa907591236ac59d49de
parent877713e9442c55e11742cdb8573bf3c8753eb4cb (diff)
downloadapp-termcast-3737f9223a7ef620ae95e614e35cb4b50c094125.tar.gz
app-termcast-3737f9223a7ef620ae95e614e35cb4b50c094125.zip
factor this out into a method
-rw-r--r--lib/App/Termcast.pm21
1 files 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