You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
fromosimportopen, read, write, O_RDWRt=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/nullTell me something: helloYou wrote hello
$
The text was updated successfully, but these errors were encountered:
xavierog
changed the title
Linux driver: consider using /dev/tty instead of stdin (and possible stderr)
Linux driver: consider using /dev/tty instead of stdin (and possibly stderr)
Feb 15, 2025
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
:The text was updated successfully, but these errors were encountered: