digitalmars.D.learn - Prevent console line advancing on user input
- anonymouse (18/18) Apr 06 2023 Wondering if this is possible? Ask a user at input and wait for
- Steven Schveighoffer (6/22) Apr 06 2023 You can't intercept raw input. It's the terminal that decides when to
- anonymouse (4/10) Apr 06 2023 [snip]
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.
Would appreciate any pointers.
Thanks
--anonymouse
Apr 06 2023
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
Apr 06 2023
On Thursday, 6 April 2023 at 14:51:43 UTC, Steven Schveighoffer wrote:On 4/6/23 4:01 AM, anonymouse wrote:[snip]Wondering if this is possible?You need to use a terminal-control library, such as `arsd.terminal` https://github.com/adamdruppe/arsd/blob/master/terminal.d -SteveThat works perfectly. Thanks.
Apr 06 2023








anonymouse <anony mouse.com>