nodejs REPL has piping issues when preview is on

89 views Asked by At

I'm trying to have a node.js eval piped to a ssh2 stream. And I'm having some interesting issues. Mainly how either ssh2 or ssh clients interpret the data. Let's take a look.

when you run the node process, you get this nice prompt node prompt

so this is how my code looks calling repl

where sshStream is a ssh2 stream, now because I'm piping the stream, this is how it looks on the other side:

tty

basically the cursor is moving down below, and not staying where it used to, if I type s, then it doesn't get fixed, and the terminal gets even more messed up, does anyone know the causes? How should I fix this?

fixNewLines is basically a pipe that replaces ('\n' into '\r\n' because apparently, that's important for the ssh protocol, otherwise you don't get the desired behaviour)

1

There are 1 answers

0
Rainb On

The reason this happens is because processes behave differently if they're on a PTY than if they're called directly, because there is no PTY, you see that behaviour, you would have to create your own Pseudo-PTY in order to correctly receive and interpret the characters as if you were on a real shell.