The problem is that some programs behave differently when stdio is connected to
a terminal(eg: python interpreter). As I said, it would be possible to implement
a full terminal emulation library for windows, but it would be far from trivial.
I can see two possible ways to attack the problem:
- Inject code into the child process to poll for $CONOUT/$CONIN data in a
separate thread and communicate with the emulator using a pipe. This is what
Console2 does.
- Take winpty approach which I haven't investigated, but I guess it involves
starting a 'pty agent'(a proxy daemon that somehow manages to get the data
from the console program)
I'm not sure if libuv devs would accept adding a flag that only works on UNIX
and is ignored on windows, but here's the code I have so far if you want to
It still needs some improvements:
- An API function to resize the child process terminal(eg:
uv_resize_terminal(uv_process_t *, int cols, int rows))
- Refactor to use `posix_openpt` which is seems to be standard posix way of
opening pseudo-terminals. The `openpty` function is non-standard and requires
an extra `-lutil` link.
- Add more tests
Note that my goal was to provide the simplest API that would behave similarly on
windows or unixes, so it has these limitations:
- All std file descriptors have to be redirected when using the
UV_PROCESS_CREATE_TERMINAL flag
- The UV_PROCESS_CREATE_TERMINAL flag also implies that the child process is
started in a new session(so it receives signals independently from the parent)
and has a controlling terminal. In windows terms it means the process
owns the console.