September 19
On Saturday, 19 September 2020 at 13:56:53 UTC, Anonymouse wrote:
> On Saturday, 19 September 2020 at 13:32:07 UTC, Paul Backus wrote:
>>
>> http://dpldocs.info/experimental-docs/std.stdio.File.setvbuf.1.html
>
> Thanks.
>
> I don't have a clone of druntime/Phobos available to me right now, so some follow-up questions.
>
> It looks like full buffering _IOFBF is the default setting, but "normal" non-Cygwin stdio certainly seems to do line buffering. Is it getting set to line buffering _IOLBF during initialisation of stdout? (Why then is Cygwin exempt?)

This isn't a druntime/Phobos thing, it's a libc thing. Phobos just provides a wrapper around it.

My guess is that libc uses something like `isatty(STDOUT_FILENO)` to determine if it should use line buffering, and that there's a bug in Cygwin that causes isatty() to always return false. If you want to know for sure, you can try looking through the Cygwin source code. [1]

> Is there a way to detect programmatically if I'm in an environment where I need to manually set line buffering?

You can check the TERM environment variable [2], or you can use the POSIX uname() function [3] to see if you're running under Cygwin specifically. If there are any other environments where you need to manually set line-buffering, you'll probably have to check for those individually as well.

[1] https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git
[2] https://cygwin.com/cygwin-ug-net/setup-env.html
[3] https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux
September 19
On Saturday, 19 September 2020 at 14:14:46 UTC, Paul Backus wrote:
> You can check the TERM environment variable [2], or you can use the POSIX uname() function [3] to see if you're running under Cygwin specifically. If there are any other environments where you need to manually set line-buffering, you'll probably have to check for those individually as well.

All right, thanks. Yes, currently I'm doing the TERM and uname thing on program start and flushing manually after every writeln if I detected Cygwin or vscode.

I think I can work with this.

September 19
On Saturday, 19 September 2020 at 14:08:39 UTC, Adam D. Ruppe wrote:
> On Saturday, 19 September 2020 at 13:56:53 UTC, Anonymouse wrote:
>> Is there a way to detect programmatically if I'm in an environment where I need to manually set line buffering?
>
> Part of the problem is the IDE console and cygwin too I believe both *look* like a pipe to the program instead of like an interactive terminal, thus why it gets block instead of line buffered.
>
> Someone once told me of a trick to detect cygwin specifically but I can't access it right now and I'm not sure it would work reliably anyway....
>
> Just yeah set your expectations low because if it was easy to tell programmatically the libc would already do it right.

Also makes sense, thanks. I already expose the option to force flushing with a --flush command-line argument, so I guess I'll keep that around (but use setvbuf when the TERM/uname thing detects a whitelisted environment).
September 19
That said, full buffering for pipes may be not all that profitable, so it makes sense to always set line buffering for pipes and leave full buffering only for file.
September 19
if(GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))==FILE_TYPE_PIPE)setvbuf()
Next ›   Last »
1 2