使用 python/浏览器进行 vt100 终端仿真
我正在尝试为 Web 浏览器构建 SSH 客户端(类似于 ajaxterm)。我已经构建了一个使用 Paramiko 的 SSHClient.invoke_shell(term='vt100 ')
以及与前端通信的 Web 服务器(HTML + AJAX)。当我通过 SSH 通道发送命令时,系统工作并显示输出,但输出包括 VT100 转义序列。
如果我理解正确的话,我从 SSH 通道获得的任何内容都应该解释为 24x80 终端窗口的命令?这意味着转义序列可能会改变颜色、清除屏幕、删除线条、改变线条的行为方式...(我找到了一个很好的列表 这里) 这意味着我不能直接清除它们?
我查看了 Ajaxterm 的源代码,但无法弄清楚如何使用 Terminal 类(因此我可以将其用于我的目的)。
问题:解释输出流并在浏览器中正确显示终端屏幕的最简单方法是什么?换句话说,是否有一个库可以解析输出并为我保留屏幕内容?
如果我误解了终端的内部工作原理,请告诉我。我过去没有太多与他们打交道的经验。 :)
I am trying to build a SSH client for the web browser (similar to ajaxterm). I have built a python backend that uses Paramiko's SSHClient.invoke_shell(term='vt100')
and a web server which communicates with a frontend (HTML + AJAX). The system works and displays output when I send commands through SSH channel, but the output includes VT100 escape sequences.
If I understand correctly, anything I get from the SSH channel should be interpreted as commands for 24x80 terminal window? Which means the escape sequences may change color, clear screen, remove lines, change the way lines behave... (I have found a good list here) Which means I can't just clear them out?
I checked out Ajaxterm's source, but couldn't figure out how Terminal class can be used (so I could use it for my purposes).
The question: what would be the easiest way to interpret the output stream and properly display the terminal screen in a browser? In other words, is there a library that parses the output and keeps the screen contents for me?
If I have misunderstood the inner workings of the terminals, please let me know. I haven't had much of experience with them in the past. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几天前我也尝试过做同样的事情。我没有完成它,但我找到了一些 python 终端模拟器库。
我选择 pyte,它有一个干净的 API 并且易于使用。 pyte 的自述文件末尾提供了执行相同工作的其他库的列表。
I've tried to do the same thing a few days ago. I didn't finished it, but I found a few python terminal emulator libs.
I choose pyte, which has a clean API and is easy to use. A list of other libs doing the same job is available at the end of pyte's README.