I'm searching for a function that will print a string before the input is made. I know this is possible with printf and gets, but I want the string to stay on the last line where the input is given. The output is handled in the main thread, the input is handled in another thread started by the main thread.
For example this is the current console window (I have input the stop-command, the '>' is the prefix string):
[12:00:00] Starting server...
>stop
When the console outputs a new line, I want the input to be always on the bottom line, like this:
[12:00:00] Starting server...
[12:00:01] Server started
>stop
I am using Embarcadero C++Builder XE2 with Win32 and VCL support.
EDIT: I'm currently using this code, resulting in printing the output after the '>' prefix:
char buf[256];
printf(">");
gets(buf);
What you are looking for is called asynchronous input/output.
What I did to accomplish this is keeping track of each key being pressed and append it to a string.
When you press backspace it deletes the last character added to the string and when you press enter it will submit the current command.
When output comes along you clear the line you were typing on, print the output, and then move the cursor down and print out what you had saved in the string.
You have to do a little work with threading if you want but I'm pretty sure I was able to accomplish most of it without too much effort.
Other possible resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With