Add os:isatty/1
Andrew Stone <[email protected]> Mon, 22 Sep 2014 14:17:09 -0400
| Newsgroups | gmane.comp.lang.erlang.patches |
|---|---|
| Message-ID | <CA+6xbK3Q_EWkjP0T_bbktvi+vmeU+0w3v17++W+FG_Tr24RNDg@mail.gmail.com> |
Hi All, I've added support for the posix 'isatty' function to the os module. This is a relatively minor addition, however it makes me wonder if there is more interest from the OTP team in adding other useful posix functions. I know personally, I'd love to have access direct from erlang for more posix functions. Let me know what you think. *https://github.com/erlang/otp/pull/480 <https://github.com/erlang/otp/pull/480>* Thanks, Andrew _______________________________________________ erlang-patches mailing list [email protected] http://erlang.org/mailman/listinfo/erlang-patches
isatty_eep_light.txt
(text/plain, 908 B)
# Why do we need this feature? The posix libc function, isatty(), is a useful function that will tell you if a file descriptor is attached to a terminal. If for instance you want to write a program that uses ansi color codes, it is not enough to just check $TERM because the output could be redirected to a file. In that case you would end up with the escape codes in the file making it harder to read and parse. By calling os:isatty/1 with stdout as it's parameter the program can ensure that it never writes escape codes to log files. # Risks or Uncertain Artifacts It uses a posix function that should be available on all platforms including Windows. The call is deprecated in favor of the C++ standard _isatty() call on Windows though. # How did you solve it? I added a bif to the os module. This seems to be the only reasonable way to do it, as the call must be in the same os process of the caller.