elvish
elvish copied to clipboard
A `file:is-tty` command would be useful
The equivalent of the POSIX test -t $fd
command would be useful. It should default to the Elvish equivalent of os.Stdout
to allow for LHS of a pipe and redirections. It should optionally accept an explicit *os.File
or vals.File
argument with any other type (e.g., a pathname string, including something like /dev/tty
) being an error.
Related #1262
For anyone inclined to implement this note that Elvish already depends on github.com/mattn/go-isatty
which provides an OS agnostic API for determining whether an open file refers to a tty.
FYI, I started work on implementing this. Which quickly revealed an obvious, in hindsight, challenge to using such a command. Consider that the POSIX test -d $fd
returns a non-zero exit status which Elvish would translate to an exception. Well, the same is going to be true for a builtin file:is-tty
that returns an error because the output stream doesn't support a value channel; regardless of whether the byte channel is open on a tty. Which means you always have to wrap this command in a try
block. Something I didn't realize when I opened this issue but should have recognized as something that would complicate using this type of command. Given the design of Elvish I don't see any way to avoid having to always use this command in a try
block but I would be thrilled to learn I was wrong.