Asynchronous Windows Console input whilst outputting
up vote
1
down vote
favorite
I'm having issues trying to read input whilst outputting at the same time. I need a server console for my game which can receive input whilst outputting and not mess up the buffer.
For example, I'm typing "Hello world" and in the process, player deaths, kills, etc. are being outputted into the console, which would result in something like:
Hello *Player killed Player2*world
Thanks in advance
c++ windows winapi console
add a comment |
up vote
1
down vote
favorite
I'm having issues trying to read input whilst outputting at the same time. I need a server console for my game which can receive input whilst outputting and not mess up the buffer.
For example, I'm typing "Hello world" and in the process, player deaths, kills, etc. are being outputted into the console, which would result in something like:
Hello *Player killed Player2*world
Thanks in advance
c++ windows winapi console
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm having issues trying to read input whilst outputting at the same time. I need a server console for my game which can receive input whilst outputting and not mess up the buffer.
For example, I'm typing "Hello world" and in the process, player deaths, kills, etc. are being outputted into the console, which would result in something like:
Hello *Player killed Player2*world
Thanks in advance
c++ windows winapi console
I'm having issues trying to read input whilst outputting at the same time. I need a server console for my game which can receive input whilst outputting and not mess up the buffer.
For example, I'm typing "Hello world" and in the process, player deaths, kills, etc. are being outputted into the console, which would result in something like:
Hello *Player killed Player2*world
Thanks in advance
c++ windows winapi console
c++ windows winapi console
edited Nov 11 at 19:33
anothermh
2,80411226
2,80411226
asked Jun 6 '09 at 15:38
Saul
662923
662923
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
4
down vote
accepted
Instead of writing output directly to the console, why not spawn a GUI window?
Then, just have one area where output is directed, and a separate input area at the bottom where you can type commands. Kinda like how an irc client would look.
If it has to be console only, I would suggest using something like ncurses (or PDCurses) to create a text based interface.
add a comment |
up vote
1
down vote
Without thinking too hard about this, it seems to me you either need a non-blocking input routine for stdin, something like getch() but just returns if there is nothing to read, which you call in a loop while also processing output, or you need two thraeds: one to read, one to write.
The input routine is non-blocking, hence the output appearing where you're inputting when you type. See my example, italics is what is outputted whilst I'm typing "Hello world"
– Saul
Jun 6 '09 at 20:05
You may use some kind of synchronization and block/buffer one while the other is happening, or just use two different areas for input and output. I highly suggest you take @AsLanFromNarnia's suggestion and opt for the latter.
– aib
Jun 7 '09 at 0:40
add a comment |
up vote
0
down vote
You're developing the console yourself, so this should be no big problem.
The console is basically a set of text lines that are being rendered. User input is echoed so the user sees wha he's typing. This means that the last line of the console is special, it is the "editable input buffer". All other lines are output. When the user hits Enter
, you execute the edit buffer. Step 1 in executing is making a private copy of the edit buffer, step 2 is clearing the edit buffer, and step 3 is copying the private copy to output.
Hence, at any moment there's only one partial line and it only changes by user input. All other lines are complete, and change on a line-by-line basis. Your program logging happens between two user inputs and therefore gets itws own line. In a multi-threaded program, this means the "Console::AddLine" function will need an internal mutex (CriticalSection for Win32).
add a comment |
up vote
0
down vote
It sounds like you need a layer between the code and your console. Create a wrapper object that does all the console I/O. When someone calls its WriteLine method, the wrapper should erase the currently displayed input (if any), write the line, and then write the input again beneath it.
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Instead of writing output directly to the console, why not spawn a GUI window?
Then, just have one area where output is directed, and a separate input area at the bottom where you can type commands. Kinda like how an irc client would look.
If it has to be console only, I would suggest using something like ncurses (or PDCurses) to create a text based interface.
add a comment |
up vote
4
down vote
accepted
Instead of writing output directly to the console, why not spawn a GUI window?
Then, just have one area where output is directed, and a separate input area at the bottom where you can type commands. Kinda like how an irc client would look.
If it has to be console only, I would suggest using something like ncurses (or PDCurses) to create a text based interface.
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Instead of writing output directly to the console, why not spawn a GUI window?
Then, just have one area where output is directed, and a separate input area at the bottom where you can type commands. Kinda like how an irc client would look.
If it has to be console only, I would suggest using something like ncurses (or PDCurses) to create a text based interface.
Instead of writing output directly to the console, why not spawn a GUI window?
Then, just have one area where output is directed, and a separate input area at the bottom where you can type commands. Kinda like how an irc client would look.
If it has to be console only, I would suggest using something like ncurses (or PDCurses) to create a text based interface.
answered Jun 6 '09 at 16:48
Fredrick Pennachi
727616
727616
add a comment |
add a comment |
up vote
1
down vote
Without thinking too hard about this, it seems to me you either need a non-blocking input routine for stdin, something like getch() but just returns if there is nothing to read, which you call in a loop while also processing output, or you need two thraeds: one to read, one to write.
The input routine is non-blocking, hence the output appearing where you're inputting when you type. See my example, italics is what is outputted whilst I'm typing "Hello world"
– Saul
Jun 6 '09 at 20:05
You may use some kind of synchronization and block/buffer one while the other is happening, or just use two different areas for input and output. I highly suggest you take @AsLanFromNarnia's suggestion and opt for the latter.
– aib
Jun 7 '09 at 0:40
add a comment |
up vote
1
down vote
Without thinking too hard about this, it seems to me you either need a non-blocking input routine for stdin, something like getch() but just returns if there is nothing to read, which you call in a loop while also processing output, or you need two thraeds: one to read, one to write.
The input routine is non-blocking, hence the output appearing where you're inputting when you type. See my example, italics is what is outputted whilst I'm typing "Hello world"
– Saul
Jun 6 '09 at 20:05
You may use some kind of synchronization and block/buffer one while the other is happening, or just use two different areas for input and output. I highly suggest you take @AsLanFromNarnia's suggestion and opt for the latter.
– aib
Jun 7 '09 at 0:40
add a comment |
up vote
1
down vote
up vote
1
down vote
Without thinking too hard about this, it seems to me you either need a non-blocking input routine for stdin, something like getch() but just returns if there is nothing to read, which you call in a loop while also processing output, or you need two thraeds: one to read, one to write.
Without thinking too hard about this, it seems to me you either need a non-blocking input routine for stdin, something like getch() but just returns if there is nothing to read, which you call in a loop while also processing output, or you need two thraeds: one to read, one to write.
answered Jun 6 '09 at 16:55
i_am_jorf
44.4k11111204
44.4k11111204
The input routine is non-blocking, hence the output appearing where you're inputting when you type. See my example, italics is what is outputted whilst I'm typing "Hello world"
– Saul
Jun 6 '09 at 20:05
You may use some kind of synchronization and block/buffer one while the other is happening, or just use two different areas for input and output. I highly suggest you take @AsLanFromNarnia's suggestion and opt for the latter.
– aib
Jun 7 '09 at 0:40
add a comment |
The input routine is non-blocking, hence the output appearing where you're inputting when you type. See my example, italics is what is outputted whilst I'm typing "Hello world"
– Saul
Jun 6 '09 at 20:05
You may use some kind of synchronization and block/buffer one while the other is happening, or just use two different areas for input and output. I highly suggest you take @AsLanFromNarnia's suggestion and opt for the latter.
– aib
Jun 7 '09 at 0:40
The input routine is non-blocking, hence the output appearing where you're inputting when you type. See my example, italics is what is outputted whilst I'm typing "Hello world"
– Saul
Jun 6 '09 at 20:05
The input routine is non-blocking, hence the output appearing where you're inputting when you type. See my example, italics is what is outputted whilst I'm typing "Hello world"
– Saul
Jun 6 '09 at 20:05
You may use some kind of synchronization and block/buffer one while the other is happening, or just use two different areas for input and output. I highly suggest you take @AsLanFromNarnia's suggestion and opt for the latter.
– aib
Jun 7 '09 at 0:40
You may use some kind of synchronization and block/buffer one while the other is happening, or just use two different areas for input and output. I highly suggest you take @AsLanFromNarnia's suggestion and opt for the latter.
– aib
Jun 7 '09 at 0:40
add a comment |
up vote
0
down vote
You're developing the console yourself, so this should be no big problem.
The console is basically a set of text lines that are being rendered. User input is echoed so the user sees wha he's typing. This means that the last line of the console is special, it is the "editable input buffer". All other lines are output. When the user hits Enter
, you execute the edit buffer. Step 1 in executing is making a private copy of the edit buffer, step 2 is clearing the edit buffer, and step 3 is copying the private copy to output.
Hence, at any moment there's only one partial line and it only changes by user input. All other lines are complete, and change on a line-by-line basis. Your program logging happens between two user inputs and therefore gets itws own line. In a multi-threaded program, this means the "Console::AddLine" function will need an internal mutex (CriticalSection for Win32).
add a comment |
up vote
0
down vote
You're developing the console yourself, so this should be no big problem.
The console is basically a set of text lines that are being rendered. User input is echoed so the user sees wha he's typing. This means that the last line of the console is special, it is the "editable input buffer". All other lines are output. When the user hits Enter
, you execute the edit buffer. Step 1 in executing is making a private copy of the edit buffer, step 2 is clearing the edit buffer, and step 3 is copying the private copy to output.
Hence, at any moment there's only one partial line and it only changes by user input. All other lines are complete, and change on a line-by-line basis. Your program logging happens between two user inputs and therefore gets itws own line. In a multi-threaded program, this means the "Console::AddLine" function will need an internal mutex (CriticalSection for Win32).
add a comment |
up vote
0
down vote
up vote
0
down vote
You're developing the console yourself, so this should be no big problem.
The console is basically a set of text lines that are being rendered. User input is echoed so the user sees wha he's typing. This means that the last line of the console is special, it is the "editable input buffer". All other lines are output. When the user hits Enter
, you execute the edit buffer. Step 1 in executing is making a private copy of the edit buffer, step 2 is clearing the edit buffer, and step 3 is copying the private copy to output.
Hence, at any moment there's only one partial line and it only changes by user input. All other lines are complete, and change on a line-by-line basis. Your program logging happens between two user inputs and therefore gets itws own line. In a multi-threaded program, this means the "Console::AddLine" function will need an internal mutex (CriticalSection for Win32).
You're developing the console yourself, so this should be no big problem.
The console is basically a set of text lines that are being rendered. User input is echoed so the user sees wha he's typing. This means that the last line of the console is special, it is the "editable input buffer". All other lines are output. When the user hits Enter
, you execute the edit buffer. Step 1 in executing is making a private copy of the edit buffer, step 2 is clearing the edit buffer, and step 3 is copying the private copy to output.
Hence, at any moment there's only one partial line and it only changes by user input. All other lines are complete, and change on a line-by-line basis. Your program logging happens between two user inputs and therefore gets itws own line. In a multi-threaded program, this means the "Console::AddLine" function will need an internal mutex (CriticalSection for Win32).
answered Jun 8 '09 at 8:53
MSalters
133k8115267
133k8115267
add a comment |
add a comment |
up vote
0
down vote
It sounds like you need a layer between the code and your console. Create a wrapper object that does all the console I/O. When someone calls its WriteLine method, the wrapper should erase the currently displayed input (if any), write the line, and then write the input again beneath it.
add a comment |
up vote
0
down vote
It sounds like you need a layer between the code and your console. Create a wrapper object that does all the console I/O. When someone calls its WriteLine method, the wrapper should erase the currently displayed input (if any), write the line, and then write the input again beneath it.
add a comment |
up vote
0
down vote
up vote
0
down vote
It sounds like you need a layer between the code and your console. Create a wrapper object that does all the console I/O. When someone calls its WriteLine method, the wrapper should erase the currently displayed input (if any), write the line, and then write the input again beneath it.
It sounds like you need a layer between the code and your console. Create a wrapper object that does all the console I/O. When someone calls its WriteLine method, the wrapper should erase the currently displayed input (if any), write the line, and then write the input again beneath it.
answered Jun 8 '09 at 20:31
Peter Ruderman
10.1k2352
10.1k2352
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f959947%2fasynchronous-windows-console-input-whilst-outputting%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown