xterm.js + ws + ssh2 不将终端调整大小信号(SIGWINCH)传输到 ssh 服务器 [英] xterm.js + ws + ssh2 not transmitting terminal resize signals (SIGWINCH) to ssh server

查看:43
本文介绍了xterm.js + ws + ssh2 不将终端调整大小信号(SIGWINCH)传输到 ssh 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处重新表述我的问题.

Rephrasing my issue here.

我有一个使用xterm.js"、ws"和ssh2"节点模块的网络应用程序.一切都很好.除了一件事:

I have a web-app using 'xterm.js', 'ws', and 'ssh2' node modules. Everything works great. Except one thing:

SIGWINCH 窗口大小调整信号不会发送到 sshd 服务器或 ssh2 流.其他 sigs、esc、ansi 工作正常.Esc[8 就消失了.

SIGWINCH window resize signal won't make it to the sshd server, or the ssh2 stream. Other sigs, esc, ansi work fine. Esc[8 just disappears.

在真正的 xterm 中,echo -e "\e[8;30;120t" 调整两端终端的大小.不在这里.sock.send("\u001b[8;30;120t") 也不会做任何事情.

In a real xterm, echo -e "\e[8;30;120t" resizes the terminal on both ends. Not here. sock.send("\u001b[8;30;120t") won't do anything either.

我的节点应用服务器上的 Console.log 显示 Escape[8(或 \e、\u001b 或 \x1b)没有成功.其他转义码也有效——箭头、鼠标点击等.

Console.log on the my node app server shows Escape[8 (or \e, \u001b, or \x1b) doesn't make it. Other escape codes work-- arrows, mouse-clicks etc.

我可以在客户端执行 term.resize(x,y),但目前必须在服务器上使用 stty.ssh2 的 pty 仅在登录时设置它们.我如何传播SIGWINCH?它被困在哪里?

I can do term.resize(x,y) on the client, but currently have to use stty on the server. Ssh2's pty sets them at login only. How do I propagate SIGWINCH? Where is it being trapped?

推荐答案

好的.所以我自己对这个问题的回答是:在浏览器中,使用 term.resize(cols,rows) 来调整本地终端的大小.通过 websocket 通过 ansi 转义序列传输列和行.然后,在节点服务器应用程序上,在 ssh2 客户端中,使用 Regexp 匹配调整大小转义序列并提取第二和第三个数字,即列数和行数('8' 是调整大小的代码).将 ssh2 客户端调整大小功能与提取的 cols 和行一起使用(告诉 ssh2 psuedoterminal 将 sigwinch 和 cols/rows 发送到 ssh 服务器).不理想,我知道如果我能找到它有更好的方法,但是如果您在浏览器中为它创建一个函数并将其添加到事件侦听器以调整窗口大小,它会很好地工作.现在,当我调整浏览器窗口的大小,或者当软键盘在移动设备上弹出或隐藏时,我的终端会话将在客户端和服务器端适当调整大小.

Ok. So my own answer to this question: In the browser, use term.resize(cols,rows) to resize the local terminal. Transmit the cols and rows via the ansi escape sequence over websocket. Then, on the node server app, in the ssh2 client, use Regexp to match resize escape sequence and extract the second and third numbers, which are the number of cols and rows (the '8' is the code for resize). Use the ssh2 client resize function with extracted cols and rows (tells the ssh2 psuedoterminal to send sigwinch and cols/rows to the ssh server). Not ideal, I know there is a better way if I could find it, but it works beautifully if you make a function in the browser for it and add it to an event listener for window resize. Now my terminal session will resize appropriately on both the client and server ends when I resize the browser window, or when the soft keyboard pops up or hides on mobile.

这篇关于xterm.js + ws + ssh2 不将终端调整大小信号(SIGWINCH)传输到 ssh 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆