Control flushing to stdout... core.osthread.Thread + arsd.terminal

aberba karabutaworld at gmail.com
Fri Jun 5 11:45:31 UTC 2020


I have this code which take two inputs. I expect "Wait, signing 
you in ..." to be written to stdout before Thread.sleep() kicks 
in but it somehow doesn't follow that sequence. I believe its a 
normal stdout behaviour since its buffered.

How can I make Thread.sleep() only run AFTER "Wait, signing you 
in ..." is written (force flushed) to stdout?

import core.thread.osthread, std.datetime;
import arsd.terminal;

void main()
{
     auto terminal = Terminal(ConsoleOutputType.linear);
     terminal.setTitle("App");

     // this is possible too but you MUST have an indexed png 
which might be hard to make if you aren't ready for it.
     // terminal.changeWindowIcon("assets/icon.png");

     terminal.writeln("hi");

     auto got = terminal.getline("Username: ");
     auto code = terminal.getline("Password: ");

     const timeInSeconds = 5;
     terminal.writeln("Wait, signing you in ...");


     Thread.sleep(timeInSeconds.seconds);


     terminal.writeln("username is ", got);
     terminal.writeln("code is ", code);
}



More information about the Digitalmars-d-learn mailing list