Testing if a file is connected to a terminal
Jakob Ovrum via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 16 19:59:27 PST 2015
On Thursday, 17 December 2015 at 03:38:31 UTC, Shriramana Sharma
wrote:
> Is there a canonical way to test in D whether stdout/stderr (or
> in general, a std.stdio.File) refers to a terminal or not?
>
> https://www.google.co.in/search?q=terminal&sitesearch=dlang.org/phobos turns out nothing.
>
> I knew of C's (or rather POSIX's) isatty, and after some
> digging I found isatty defined under core.sys.posix.unistd, and
> I suppose I can just pass to it the output of
> std.stdio.File.getFP.
>
> Is there any other way to do the desired test? Or is this the
> recommended way?
We don't have any terminal functionality in Phobos at this time,
so using isatty directly is the way to go.
There are some terminal libraries on Github (like consoled) but I
have to say I think they're uninspiring in terms of quality and
presentation.
More information about the Digitalmars-d-learn
mailing list