Check output device is a terminal: Difference between revisions
Content added Content deleted
(→{{header|Julia}}: A new entry for Julia) |
(J) |
||
Line 117: | Line 117: | ||
<lang js>node -p -e "Boolean(process.stdout.isTTY)" |
<lang js>node -p -e "Boolean(process.stdout.isTTY)" |
||
true</lang> |
true</lang> |
||
=={{header|J}}== |
|||
<lang J>3=nc<'wd'</lang> |
|||
Explanation: |
|||
J does not have a concept of an "output device", so we approximate that by seeing whether we have bothered to define a the code which typically does graphical output. |
|||
The use of the phrase "output device" suggests that we are thinking about something like the unix `isatty` command. Here, stdout might be a file or might be a terminal. But in J we are often hosting our own user interaction environment. It's not uncommon for a J user to be on a web page where hitting enter sends a form request to a J interpreter which in turn composes an updated html presentation of current state which it sends to the browser. Or, the J user might be talking to a Java program which similarly wraps the J session (though this is older technology at this point). Or, the J user might be interacting with Qt. Or, sure, we might be talking to a tty and J might be sending its output straight to the tty. (But we can't know if that tty is hosted in emacs, running under control of a script on a remote machine via ssh, talking directly to a human user who happens to be in direct control of the session, or whatever else...) |
|||
The point being that in the general case the J programmer cannot know whether the concept of "terminal" has any relevance to the user. |
|||
But, like everyone else, we can certainly use heuristics. |
|||
But, correctness requires us to keep in mind that these will only be heuristics, and will sometimes be incorrect (hopefully not often enough to matter a lot...). |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |