[erlang-patches] Add os:isatty/1

Andrew Stone andrew.j.stone.1@REDACTED
Mon Sep 22 20:17:09 CEST 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20140922/d019796d/attachment.htm>
-------------- next part --------------
# 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.


More information about the erlang-patches mailing list