0

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?

Grief
  • 1,839
  • 1
  • 21
  • 40

1 Answers1

1

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.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Got it. There lays the whole layer I was not aware of. I was able to check it with `python -c 'import pty; pty.spawn("mc", stdin_read=lambda x: 0)'` - mc doesn't respond to anything. Great! – Grief Aug 07 '18 at 13:20