Description
In the beginning, the Linux driver used to write to stdout; this was changed to stderr to enable piping between a Textual producer and an external consumer.
As these lines are being written, the Linux driver still relies on stdin to read terminal events, making it difficult to enable piping between an arbitrary producer and a Textual consumer. This was still achieved in e.g. toolong's cli.py by combining /dev/tty
and various tricks (temporary file, fork and reexec).
It should be possible to make these tricks unnecessary by having the Linux driver systematically use /dev/tty
for both input and output (with possible failover to stdin and stderr if /dev/tty is somehow unavailable, or if a dedicated environment variable says so).
That would leave all three standard file descriptors (stdin, stdout, stderr) available to developers and end users for regular use, e.g. mytextualapp < mydata > myresults 2> myerrors
while still being able to read events from the controlling terminal and draw widgets to it.
This is best demonstrated by a Python snippet interacting with the terminal despite having all three standard file descriptors pointing to /dev/null
:
test.py
:
from os import open, read, write, O_RDWR
t = open("/dev/tty", O_RDWR)
write(t, b"Tell me something: ")
v = read(t, 512)
write(t, b"You wrote " + v)
$ python3 test.py < /dev/null 1> /dev/null 2> /dev/null
Tell me something: hello
You wrote hello
$