From 9657c731c7c05350970ae3bc0c9bc6d7aadd8efe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ren=C3=A9=20Jochum?= Date: Thu, 7 Jun 2018 14:29:26 +0200 Subject: [PATCH] Poll the size of the terminal and resize if needed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: René Jochum --- PVE/APIClient/Commands/lxc.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/PVE/APIClient/Commands/lxc.pm b/PVE/APIClient/Commands/lxc.pm index e0d21ae..f0c85f7 100644 --- a/PVE/APIClient/Commands/lxc.pm +++ b/PVE/APIClient/Commands/lxc.pm @@ -262,8 +262,24 @@ __PACKAGE__->register_method ({ my $ctrl_a_pressed_before = 0; + my $winch_received = 0; + $SIG{WINCH} = sub { $winch_received = 1; }; + + my $check_terminal_size = sub { + my ($ncols, $nrows) = PVE::PTY::tcgetsize(*STDIN); + if ($ncols != $columns or $nrows != $rows) { + $columns = $ncols; + $rows = $nrows; + $frame = $create_websockt_frame->("1:$columns:$rows:"); + $full_write->($web_socket, $frame); + } + $winch_received = 0; + }; + while (1) { while(my @ready = $select->can_read(3)) { + $check_terminal_size->() if $winch_received; + foreach my $fh (@ready) { if ($fh == $web_socket) { @@ -300,6 +316,8 @@ __PACKAGE__->register_method ({ } } } + $check_terminal_size->() if $winch_received; + # got timeout $full_write->($web_socket, $create_websockt_frame->("2")); # ping server to keep connection alive } -- 2.39.2