From ae3bc41c88ef9a06a86b6b36d09b9f13cf9863e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Fri, 10 Apr 2026 16:44:49 +0800 Subject: [PATCH] Add files via upload --- web/static/js/terminal.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/web/static/js/terminal.js b/web/static/js/terminal.js index e93adf5c..1d3b37a2 100644 --- a/web/static/js/terminal.js +++ b/web/static/js/terminal.js @@ -121,6 +121,13 @@ ws.onopen = function () { if (tab.term) { tab.term.focus(); + // Send the actual terminal dimensions to the backend immediately + // so the PTY size matches what xterm.js is displaying. + if (tab.term.cols && tab.term.rows) { + try { + ws.send(JSON.stringify({ type: 'resize', cols: tab.term.cols, rows: tab.term.rows })); + } catch (e) {} + } } }; @@ -225,6 +232,14 @@ } } + function sendResize() { + if (tab.ws && tab.ws.readyState === WebSocket.OPEN && term.cols && term.rows) { + try { + tab.ws.send(JSON.stringify({ type: 'resize', cols: term.cols, rows: term.rows })); + } catch (e) {} + } + } + term.onData(function (data) { // Ctrl+L:本地清屏,同时把 ^L 也发给后端 if (data === '\x0c') { @@ -235,6 +250,12 @@ sendToWS(data); }); + // Notify backend when the terminal is resized so the PTY dimensions stay in sync. + // This is critical for full-screen programs like vi/vim/less to render correctly. + term.onResize(function (size) { + sendResize(); + }); + tab.term = term; tab.fitAddon = fitAddon; // 立即建立 WebSocket,让后端 PTY/Shell 马上启动并输出提示符;