Re: stdout - autoflushing

2013-12-06 Thread Dejan Lekic
Benji wrote:

 Hello,
 in order to have correctly displayed output (before reading
 something from stdin),
 I must call stdout.flush().
 Sometimes, it's really annoying, especially when it is necessarry
 to call it 10 times.
 
 For example:
 write(Enter some string: );
 stdout.flush();
 string a = readln();
 write(And again please: );
 stdout.flush();
 string b = readln();
 ...
 
 Is there any way to prevent this?

I doubt. Your IDE is buffering application's streams.

-- 
Dejan Lekic
dejan.lekic (a) gmail.com
http://dejan.lekic.org


Re: stdout - autoflushing

2013-12-06 Thread Adam D. Ruppe

On Friday, 6 December 2013 at 20:39:22 UTC, Dejan Lekic wrote:

Benji wrote:

Is there any way to prevent this?


I doubt. Your IDE is buffering application's streams.


You know though, this happens often enough that maybe we should 
just throw in a stdout.flush to the global readln function. I 
wouldn't put it on File.readln since that's likely wrong anyway, 
but on the global one it is probably what people want/expect 
anyway.


Re: stdout - autoflushing

2013-12-04 Thread Benji

On Tuesday, 3 December 2013 at 21:47:19 UTC, Adam D. Ruppe wrote:

On Tuesday, 3 December 2013 at 20:36:22 UTC, Benji wrote:

I am using Xubuntu, 64bit, and GDC as compiler


Any IDE? I've seen ide consoles buffer differently because the 
runtime sees the target as a pipe instead of a user-interactive 
terminal.


I'm using using Eclipse Kepler Standard(4.3).
I tryied it via shell and everything worked fine also without 
stdout.flush().




Re: stdout - autoflushing

2013-12-04 Thread John Colvin

On Tuesday, 3 December 2013 at 21:23:19 UTC, Ali Çehreli wrote:

On 12/03/2013 12:36 PM, Benji wrote:

On Tuesday, 3 December 2013 at 19:33:47 UTC, Ali Çehreli wrote:

On 12/03/2013 09:12 AM, Benji wrote:

Hello,
in order to have correctly displayed output (before reading 
something

from stdin),
I must call stdout.flush().


I am surprised that you need that. What is your platform?

Normally, stdin and stdout are tied. Reading from stdin 
flushes

stdout automatically.

Ali


I am using Xubuntu, 64bit, and GDC as compiler


I've known this to be the case for cin and cout of C++. So, 
I've been assuming that to be universally true. Apparently not 
for C and D behavior is based on C. I wish std.stdio gave us 
C++'s 'tie'.


Ali

P.S. This makes some of the examples at ddili.org incorrect as 
I never call flush. :-/


The 'tie' is sometimes convenient, but it's not good in Unix 
style stdin/stout piping or similar situations with lots of 
simultaneous input and output.


stdout - autoflushing

2013-12-03 Thread Benji

Hello,
in order to have correctly displayed output (before reading 
something from stdin),

I must call stdout.flush().
Sometimes, it's really annoying, especially when it is necessarry 
to call it 10 times.


For example:
write(Enter some string: );
stdout.flush();
string a = readln();
write(And again please: );
stdout.flush();
string b = readln();
...

Is there any way to prevent this?


Re: stdout - autoflushing

2013-12-03 Thread H. S. Teoh
On Tue, Dec 03, 2013 at 06:12:20PM +0100, Benji wrote:
 Hello,
 in order to have correctly displayed output (before reading
 something from stdin),
 I must call stdout.flush().
 Sometimes, it's really annoying, especially when it is necessarry to
 call it 10 times.
 
 For example:
 write(Enter some string: );
 stdout.flush();
 string a = readln();
 write(And again please: );
 stdout.flush();
 string b = readln();
 ...
 
 Is there any way to prevent this?

What about:

void prompt(A...)(string fmt, A args)
{
writef(fmt, args);
stdout.flush();
return readln();
}

auto a = prompt(Enter your name: );
auto b = prompt(Enter your age: ).to!int;
... // etc.


T

-- 
If you think you are too small to make a difference, try sleeping in a closed 
room with a mosquito. -- Jan van Steenbergen


Re: stdout - autoflushing

2013-12-03 Thread Benji

On Tuesday, 3 December 2013 at 17:49:32 UTC, H. S. Teoh wrote:

On Tue, Dec 03, 2013 at 06:12:20PM +0100, Benji wrote:

Hello,
in order to have correctly displayed output (before reading
something from stdin),
I must call stdout.flush().
Sometimes, it's really annoying, especially when it is 
necessarry to

call it 10 times.

For example:
write(Enter some string: );
stdout.flush();
string a = readln();
write(And again please: );
stdout.flush();
string b = readln();
...

Is there any way to prevent this?


What about:

void prompt(A...)(string fmt, A args)
{
writef(fmt, args);
stdout.flush();
return readln();
}

auto a = prompt(Enter your name: );
auto b = prompt(Enter your age: ).to!int;
... // etc.


T


Thanks, I didn't think about that (I'm beginner)


Re: stdout - autoflushing

2013-12-03 Thread Ali Çehreli

On 12/03/2013 09:12 AM, Benji wrote:

Hello,
in order to have correctly displayed output (before reading something
from stdin),
I must call stdout.flush().


I am surprised that you need that. What is your platform?

Normally, stdin and stdout are tied. Reading from stdin flushes stdout 
automatically.


Ali



Re: stdout - autoflushing

2013-12-03 Thread Benji

On Tuesday, 3 December 2013 at 19:33:47 UTC, Ali Çehreli wrote:

On 12/03/2013 09:12 AM, Benji wrote:

Hello,
in order to have correctly displayed output (before reading 
something

from stdin),
I must call stdout.flush().


I am surprised that you need that. What is your platform?

Normally, stdin and stdout are tied. Reading from stdin 
flushes stdout automatically.


Ali


I am using Xubuntu, 64bit, and GDC as compiler


Re: stdout - autoflushing

2013-12-03 Thread Ali Çehreli

On 12/03/2013 12:36 PM, Benji wrote:

On Tuesday, 3 December 2013 at 19:33:47 UTC, Ali Çehreli wrote:

On 12/03/2013 09:12 AM, Benji wrote:

Hello,
in order to have correctly displayed output (before reading something
from stdin),
I must call stdout.flush().


I am surprised that you need that. What is your platform?

Normally, stdin and stdout are tied. Reading from stdin flushes
stdout automatically.

Ali


I am using Xubuntu, 64bit, and GDC as compiler


I've known this to be the case for cin and cout of C++. So, I've been 
assuming that to be universally true. Apparently not for C and D 
behavior is based on C. I wish std.stdio gave us C++'s 'tie'.


Ali

P.S. This makes some of the examples at ddili.org incorrect as I never 
call flush. :-/


Re: stdout - autoflushing

2013-12-03 Thread Jesse Phillips

On Tuesday, 3 December 2013 at 20:36:22 UTC, Benji wrote:

On Tuesday, 3 December 2013 at 19:33:47 UTC, Ali Çehreli wrote:

On 12/03/2013 09:12 AM, Benji wrote:

Hello,
in order to have correctly displayed output (before reading 
something

from stdin),
I must call stdout.flush().


I am surprised that you need that. What is your platform?

Normally, stdin and stdout are tied. Reading from stdin 
flushes stdout automatically.


Ali


I am using Xubuntu, 64bit, and GDC as compiler


I haven't seen this behavior, though I haven't used GDC (debian 
is close enough right). This has been how I've retrieved user 
data:

https://github.com/JesseKPhillips/JPDLibs/blob/cmdln/cmdln/interact.d#L60


Re: stdout - autoflushing

2013-12-03 Thread Adam D. Ruppe

On Tuesday, 3 December 2013 at 20:36:22 UTC, Benji wrote:

I am using Xubuntu, 64bit, and GDC as compiler


Any IDE? I've seen ide consoles buffer differently because the 
runtime sees the target as a pipe instead of a user-interactive 
terminal.