- 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).
- 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).
- 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…