简体   繁体   English

如何结合 node-pty 和 xterm

[英]How to combine node-pty and xterm

I added a terminal to my web application using node-pty on the server, ng-termianl (xterm.js) on the client and socket.io for the communication.我在我的 web 应用程序中添加了一个终端,使用服务器上的 node-pty、客户端上的 ng-termianl (xterm.js) 和 socket.io 进行通信。 I have it basically working but I have some issues and maybe I'm making things to complicated so here are some questions:我基本上可以正常工作,但我有一些问题,也许我让事情变得复杂,所以这里有一些问题:

  1. What tasks do I need to implement in the xterm and what should I expect node-pty to handle.我需要在 xterm 中实现哪些任务以及我应该期望 node-pty 处理什么。
  • create a history buffer to handle up/down arrows.创建一个历史缓冲区来处理向上/向下箭头。
  • create the terminal prompt创建终端提示符
  • hand left and right arrow手左右箭头
  1. When listinging to the data event in node-pty I get both the echoed command,the response, and the new terminal line.在 node-pty 中列出数据事件时,我得到了回显命令、响应和新的终端行。 What is the the best way to filter out any data event that is not the respose to an issued command?过滤掉任何不是对发出命令的响应的数据事件的最佳方法是什么? Sometimes the echoed command is有时回显的命令是

  2. How do I choose a value for the node-pty column count?如何为 node-pty 列数选择一个值? Do the number of pty columns need to match up with the number of columns in the xterm? pty 列的数量是否需要与 xterm 中的列数匹配? If the command the user types in the xterm is long then the echoed command in jumbled in the pty echo of the issued command.如果用户在 xterm 中键入的命令很长,则回显的命令会在发出的命令的 pty 回显中混乱。

  1. What tasks do I need to implement in the xterm and what should I expect node-pty to handle.我需要在 xterm 中实现哪些任务以及我应该期望 node-pty 处理什么。

xterm.js : xterm.js

  • Terminal.write That's where the incoming data from the PTY should be written to. Terminal.write那是来自 PTY 的传入数据应该被写入的地方。
  • Terminal.onData Event containing data from the user (keyboard input on the terminal). Terminal.onData包含来自用户的数据的事件(终端上的键盘输入)。 Should be written to the PTY.应写入 PTY。

These are the minimum requirements to get a working PTY connection.这些是获得有效 PTY 连接的最低要求。 There are more goodies like addons to get a more full featured experience.还有更多的好东西,比如插件,可以获得更全面的体验。 Also see the demo project in the repo.另请参阅 repo 中的演示项目

PTY : :
A PTY on master side has mainly 2 interesting interface parts - the IO byte stream (can be assumed to be UTF8 these days) and a way to get/set the terminal size.主端的 PTY 主要有 2 个有趣的接口部分 - IO 字节 stream(现在可以假设为 UTF8)和获取/设置终端大小的方法。

  • create a history buffer to handle up/down arrows.创建一个历史缓冲区来处理向上/向下箭头。
  • create the terminal prompt创建终端提示符
  • hand left and right arrow手左右箭头

For a terminal driven behind the TTY interface (PTY is a special case of that) these things are handled by the application currently running in the foreground (like the shell itself).对于在 TTY 接口后面驱动的终端(PTY 是一种特殊情况),这些事情由当前在前台运行的应用程序处理(如 shell 本身)。 The foreground application is in control of a history buffer, prompt printing, what to do with arrow keys and so on.前台应用程序控制历史缓冲区、提示打印、如何使用箭头键等。 As a cmdline app developer you may care for those things (slave side of PTY), but not as a terminal integrator (master side of PTY).作为 cmdline 应用程序开发人员,您可能会关心这些事情(PTY 的从属端),但作为终端集成商(PTY 的主控端)则不然。

  1. When listinging to the data event in node-pty I get both the echoed command,the response, and the new terminal line.在 node-pty 中列出数据事件时,我得到了回显命令、响应和新的终端行。 What is the the best way to filter out any data event that is not the respose to an issued command?过滤掉任何不是对发出命令的响应的数据事件的最佳方法是什么? Sometimes the echoed command is有时回显的命令是

xterm.js is a dumb terminal, thus has no means to directly output data from user input, instead relies on proper echoing. xterm.js 是一个哑终端,因此无法直接从用户输入中获取 output 数据,而是依赖于适当的回显。 The echoing itself is a feature by the TTY kernel interface and should not be filtered, unless you want silent input (yet that is not the way to do it).回显本身是 TTY kernel 接口的一项功能,不应被过滤,除非您想要静默输入(但这不是这样做的方法)。

  1. How do I choose a value for the node-pty column count?如何为 node-pty 列数选择一个值? Do the number of pty columns need to match up with the number of columns in the xterm? pty 列的数量是否需要与 xterm 中的列数匹配? If the command the user types in the xterm is long then the echoed command in jumbled in the pty echo of the issued command.如果用户在 xterm 中键入的命令很长,则回显的命令会在发出的命令的 pty 回显中混乱。

Yes, the size in columns x rows should always be the same on xterm.js and the PTY, or weird output bugs will happen.是的,xterm.js 和 PTY 上columns x rows大小应该始终相同,否则会发生奇怪的 output 错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM