Poll the size of the terminal and resize if needed
authorRené Jochum <r.jochum@proxmox.com>
Thu, 7 Jun 2018 12:29:26 +0000 (14:29 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 8 Jun 2018 04:37:41 +0000 (06:37 +0200)
Signed-off-by: René Jochum <r.jochum@proxmox.com>
PVE/APIClient/Commands/lxc.pm

index e0d21ae..f0c85f7 100644 (file)
@@ -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
            }