[pve-devel] [PATCH pve-client] Poll the size of the terminal and resize if needed

René Jochum r.jochum at proxmox.com
Thu Jun 7 13:17:59 CEST 2018


Signed-off-by: René Jochum <r.jochum at proxmox.com>
---
 PVE/APIClient/Commands/lxc.pm | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/PVE/APIClient/Commands/lxc.pm b/PVE/APIClient/Commands/lxc.pm
index e0d21ae..058660c 100644
--- a/PVE/APIClient/Commands/lxc.pm
+++ b/PVE/APIClient/Commands/lxc.pm
@@ -262,8 +262,25 @@ __PACKAGE__->register_method ({
 
 	    my $ctrl_a_pressed_before = 0;
 
+	    my $last_check = time();
+	    my $check_terminal_size = sub {
+		my $now = time();
+		if ($now > $last_check + 5) {
+		    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);
+		    }
+		    $last_check = $now;
+		}
+	    };
+
 	    while (1) {
 		while(my @ready = $select->can_read(3)) {
+		    $check_terminal_size->();
+
 		    foreach my $fh (@ready) {
 
 			if ($fh == $web_socket) {
@@ -300,6 +317,8 @@ __PACKAGE__->register_method ({
 			}
 		    }
 		}
+		$check_terminal_size->();
+
 		# got timeout
 		$full_write->($web_socket, $create_websockt_frame->("2")); # ping server to keep connection alive
 	    }
-- 
2.11.0




More information about the pve-devel mailing list