I am experimenting with wrapping console applications into a synthetic environment like I though multiplexers do. But I've noticed that apps like mc (midnight commander) written with the use of S-Lang library are able to get partial keyboard state even if their stdin is not attached to TTY.
For example, cat /dev/zero|/usr/bin/mc doesn't affect the operability of the app at all.
I tried to understand how does mc works in tmux but I cannot find the place where does the magic happen in the code of these three components (mc, tmux and slang).
The question is how can I programmatically start an app like mc so that I would be able to interact with it via file descriptor while the actual stdin won't be available to that app at all?
They're checking if their standard input comes from a terminal, using
isatty, and if not closing the input, reopening/dev/tty.Unless an application takes special actions in that sort of approach, the piped input is lost. For instance, it could read the data into a buffer and do something useful with it.