On 4/6/23 4:01 AM, anonymouse wrote:
Wondering if this is possible? Ask a user at input and wait for response:
write("Is the sky blue? ");
readf!" %s\n"(response);
If the user's response is correct, I'd like to change the color of
provided response to indicate it was correct then advance to the next
line and ask a different question.
If the user's response is incorrect, I'd like to clear the line and
repeat the question without advancing down the screen vertically.
I'm assuming it can be done by intercepting all input before the console
processes them and outputting a '\r', a blank line the length of the
screen, and another '\r' to get back to the beginning before reprinting
the question. But I have no idea how to intercept the raw input.
You can't intercept raw input. It's the terminal that decides when to
send you the line of text, you cannot control it via `stdin`.
You need to use a terminal-control library, such as `arsd.terminal`
https://github.com/adamdruppe/arsd/blob/master/terminal.d
-Steve