34 ms·
> The shell could use pipes to intercept all output, and relay it onto the terminal. While it works in trivial cases like whoami, some programs check whether st
by qwerty456127 6y ago
> The shell could use pipes to intercept all output, and relay it onto the terminal. While it works in trivial cases like whoami, some programs check whether stdout is a terminal and change their behavior, others go over your head and talk to the TTY directly (e.g. ssh‘s password prompt), and some use TTY specific ioctls that fail if the output is not a TTY, such as querying window size or disabling local echo for password input.
Where do I read more about this? I'd like to understand terminals, pipes and the differences. And how does the mouse (in case of terminal apps which support mouse, e.g. Midnight Commander) fit in this model.
- macintux 6y agoMy goto book for these concepts has always been APUE, although the 2nd edition at least doesn’t cover mice that I can see. http://www.apuebook.com/ http://www.apuebook.com/
- Dylan16807 6y agoA pipe is like a special file that takes text from one program and puts it into another. A terminal is either a physical object with a screen and a keyboard, or software that pretends to be such an object. The terminal can display text, but also certain sequences of text do special things. For example, if the terminal receives the character for the escape key followed by [?1000h then it doesn't display it. Instead it turns on mouse click support. So a program connected to your terminal that wants mouse support can send that sequence. Then if you click, your terminal types an escape key, followed by [M, followed by three characters to say what buttons you're holding and where the mouse is located. Now the program will know you clicked.
- qwerty456127 6y agoThank you very much, now I have an idea of how does mouse support work in a Linux terminal. However, I still don't understand how does a program know it's connected to a terminal rather than some pipes.
- surajrmal 6y agoBoth the terminal or pipe show up as a preopened file descriptor to your process. You can pass that file descriptor to the isatty posix function call which will inform you whether the file is a tty (in most cases a terminal) or not.