Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

xtermjs - 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. 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.
  • 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. 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? Do the number of pty columns need to match up with the number of columns in the 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.

question from:https://stackoverflow.com/questions/66058499/how-to-combine-node-pty-and-xterm

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. What tasks do I need to implement in the xterm and what should I expect node-pty to handle.

xterm.js:

  • Terminal.write That's where the incoming data from the PTY should be written to.
  • Terminal.onData Event containing data from the user (keyboard input on the terminal). Should be written to the PTY.

These are the minimum requirements to get a working PTY connection. There are more goodies like addons to get a more full featured experience. Also see the demo project in the 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.

  • 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). 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).

  1. When listinging to the data event in node-pty I get both the echoed command,the response, and the new terminal line. 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. 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).

  1. How do I choose a value for the node-pty column count? Do the number of pty columns need to match up with the number of columns in the 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.

Yes, the size in columns x rows should always be the same on xterm.js and the PTY, or weird output bugs will happen.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...