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);
}

Reply via email to