-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A tty? function to use in scripts #911
Conversation
@arbscht I think this looks good. Apart from the two comments above, there is also some site documentation that is manually maintained under the You can also add an entry to the I don't see anything like this in Clojure, so I suspect there is no precedent to follow. (Perhaps in Clojure, you would delegate to some Java functionality using interop.) Also, it doesn't seem possible to do something like |
Oh, another thought: There are now a bunch of file predicates that have been recently added to |
Just quickly, are these comments on the commit? I can't see any. (If you started a review you might need to submit the whole review.) |
Right, I think
Nothing like this is builtin in Clojure or Java as far as I know. You could use
Yeah, the PR doesn't support it but I do want to be able to use We can probably support it at least for Readers and Writers for |
@arbscht I doubt it would help with thinking through this, but I wanted to mention that some of the underlying file open operations produce file descriptors, and those are returned as string representations (simply because they are 64-bit quantities that wouldn't fit in a JavaScript number). So, for example:
I don't see how this would lead to figuring out something with respect to I suspect you are right, in that using |
Because planck is useful in scripting contexts, it may be executed sometimes in a pipeline and sometimes not. It would be useful to be able to detect whether stdin/stdout is a tty or not, in order to adapt script behavior.
Example use case: I may want a script that:
read-line
, say) if there is an upstream pipeCurrently in planck, there seems to be no builtin way to detect stdin being a tty, so such a script running outside a pipe, that expects to read lines from stdin, will hang until there is interactive user input at
read-line
.Fine downstream of a pipe:
Waits without a pipe:
... until I type a line of input:
(I'd rather have
$ ./echo.cljs
print a help message, say.)In essence, I am looking for something capable of this:
For now, one workaround is to use a bash trampoline to execute
test -t 0
and pass that in via*command-line-args*
to the planck script. e.g.But it would be nicer to have access to
isatty
from<unistd.h>
and gain functionality similar to Python'sos.isatty
or Node'sTTY.isatty
.This PR is a proof-of-concept implementation for discussion. It adds a
planck.core/tty?
function as in theis-stdin-tty.cljs
example above.Have I missed some other way of achieving this? Is it reasonable to expect a builtin function for this?