play-with-docker.github.io icon indicating copy to clipboard operation
play-with-docker.github.io copied to clipboard

resize on the pty (almost there)

Open keesj opened this issue 4 years ago • 1 comments

Hi,

Resize is almost working but not quite fully. I am creating a website based in the JS/HTML/CSS code in this repository. The terminal resizing using jquery (but also when resizing the window) causes calls to pwd.resize. Here I see client that the terminal is resized on the client side and I do not observe any communication to the server (monitoring websockets).

As a result of that the doing something like vim the terminal does not have the correct size. Interestingly enough if I type "resize" in the terminal the correct size is detected. I think that a signal needs to be sent to the backed and a signal need to be send to the PTY process.

Searching for an answer I do see some hints this is indeed what is needed

https://github.com/xtermjs/xterm.js/issues/3092 https://stackoverflow.com/questions/63230001/how-does-sigwinch-pass-through-bash

keesj avatar Jul 12 '21 06:07 keesj

More debugging shows the code worked on pwd. I created the following "fix" to send a "instance viewport resize on resize".

diff --git a/src/index.ts b/src/index.ts
index 29e51ee..aa767ff 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -237,10 +237,10 @@ class PWD extends EventEmitter {
         self.instanceBuffer[name] += data;
       }
     });
     // Resize all terminals
     this.socket.on("instance viewport resize", function (cols, rows) {
       // Resize all terminals
       for (var name in self.instances) {
         self.instances[name].terms.forEach(function (term) {
           term.resize(cols, rows);
@@ -286,6 +286,8 @@ class PWD extends EventEmitter {
           if (t.element.clientWidth) {
             t.fitAddon.fit();
           }
+          const dim = t.fitAddon.proposeDimensions();
+          this.socket.emit('instance viewport resize', dim.cols, dim.rows);
         }, 300);
       });
     });

keesj avatar Jul 12 '21 09:07 keesj