Ensure interactive tty modes are set ASAP

It is critical that we ensure our interactive tty modes are in effect at
the earliest possible moment. This achieves that goal and is harmless if
stdin is not tied to a tty. The reason for doing this is to ensure that
\r characters are not converted to \n if we're running on the slave side
of a pty controlled by a program like tmux that is stuffing keystrokes
into the pty before we issue our first prompt.
This commit is contained in:
Kurtis Rader 2015-12-04 18:51:06 -08:00 committed by ridiculousfish
parent d65c63322e
commit 16c34b387f

View file

@ -1045,6 +1045,15 @@ void reader_init()
shell_modes.c_cc[VDSUSP] = _POSIX_VDISABLE;
#endif
#endif
// We don't use term_steal because this can fail if fd 0 isn't associated
// with a tty and this function is run regardless of whether stdin is tied
// to a tty. This is harmless in that case. We do it unconditionally
// because disabling ICRNL mode (see above) needs to be done at the
// earliest possible moment. Doing it here means it will be done within
// approximately 1 ms of the start of the shell rather than 250 ms (or
// more) when reader_interactive_init is eventually called.
tcsetattr(STDIN_FILENO, TCSANOW,&shell_modes);
}