www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Testing if a file is connected to a terminal

reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
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?

-- 
Shriramana Sharma, Penguin #395953
Dec 16 2015
parent reply Jakob Ovrum <jakobovrum gmail.com> writes:
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.
Dec 16 2015
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Thursday, 17 December 2015 at 03:59:27 UTC, Jakob Ovrum wrote:
 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.
Can you be any more specific about that?
Dec 16 2015
parent reply Jakob Ovrum <jakobovrum gmail.com> writes:
On Thursday, 17 December 2015 at 04:05:57 UTC, Adam D. Ruppe 
wrote:
 On Thursday, 17 December 2015 at 03:59:27 UTC, Jakob Ovrum 
 wrote:
 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.
Can you be any more specific about that?
Where's the reference documentation?
Dec 16 2015
next sibling parent Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
Jakob Ovrum wrote:

 Where's the reference documentation?
There's a README: http://code.dlang.org/packages/consoled, and the source does seem to have DDoc comments... -- Shriramana Sharma, Penguin #395953
Dec 16 2015
prev sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Thursday, 17 December 2015 at 05:01:15 UTC, Jakob Ovrum wrote:
 Where's the reference documentation?
In the source... but yeah, good point. I'm working on writing docs for a lot of my stuff. Terminal is still completely messed up http://arsdnet.net/arsd/terminal.html cgi is meh but there: http://arsdnet.net/arsd/cgi.html simpledisplay is the one I've spent the most time on so far: http://arsdnet.net/arsd/simpledisplay.html I'm pretty happy with how terminal.d works, but indeed the docs are still awful.
Dec 17 2015