pty.js
pty.js copied to clipboard
Disable stdin echo
When using pty.js the exec command (fork, spawn, and so on..) shows the echo of the input by stdout by default. If you are working with interactive applications it is very useful disable this echo.
We have corrected this issue adding this code in the file pty.cc in the line 178 (approximately).
/* Ensure that terminal echo is switched off so that we
do not get back from the spawned process the same
messages that we have sent it. */
struct termios orig_termios;
if (tcgetattr (STDIN_FILENO, &orig_termios) < 0) {
perror ("ERROR getting current terminal's attributes");
_exit(1);
}
orig_termios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
orig_termios.c_oflag &= ~(ONLCR);
if (tcsetattr (STDIN_FILENO, TCSANOW, &orig_termios) < 0) {
perror ("ERROR setting current terminal's attributes");
_exit(1);
}
It would be very useful provide the disable echo as a configuration option.
Thank you so much for making your pty software available.
@joapaspe Could you please provide more information or even better a pull request, so we can correct this issue ?
I'm currently using pty.js for a project and it's an issue I have myself. If you could provide a little more insight I would be willing to spend the time to create a pull request to fix it myself.
Thanks in advance for your help
:thumbsup: would like this feature myself
Here is a patch for a modern version. I've commented ONLCR flag because this was exactly why I had to use pty.js. And this is still a kludge without proper bindings to set flags on the fly.
diff --git a/frontend/pty.js/src/unix/pty.cc b/frontend/pty.js/src/unix/pty.cc
index bc50f5d..0f0cb12 100644
--- a/frontend/pty.js/src/unix/pty.cc
+++ b/frontend/pty.js/src/unix/pty.cc
@@ -195,6 +195,23 @@ NAN_METHOD(PtyFork) {
}
}
+ /* Ensure that terminal echo is switched off so that we
+ do not get back from the spawned process the same
+ messages that we have sent it. */
+ struct termios orig_termios;
+ if (tcgetattr (STDIN_FILENO, &orig_termios) < 0) {
+ perror ("ERROR getting current terminal's attributes");
+ _exit(1);
+ }
+
+ orig_termios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
+// orig_termios.c_oflag &= ~(ONLCR);
+
+ if (tcsetattr (STDIN_FILENO, TCSANOW, &orig_termios) < 0) {
+ perror ("ERROR setting current terminal's attributes");
+ _exit(1);
+ }
+
pty_execvpe(argv[0], argv, env);
perror("execvp(3) failed.");