Chronophylos
Chronophylos

Reputation: 21

User Input into Console while outputting text

I'm writing a chat. My problem is that when User A is typing their Message User B is already done with his. User A, still typing, receives the Message and it's messing up his Console Window.

I could wait until User A finishes typing his Message until I display User B's Message but that would be too easy. I read that it is possible to create two separate Console Windows (one for Input, one for Output).

Is there a way to do that?

For example two different threads access the Console Window with two different Cursors.

It seems like this is possible in ruby but I'm writing in C++.

Upvotes: 1

Views: 447

Answers (1)

LawfulEvil
LawfulEvil

Reputation: 2347

In the "old days" there were a lot of DOS console sorts of programs which moved the cursor around to draw text on various places on the screen. You could do similar things. Assuming the console window is 25 lines tall, you could make 20 of them for a "history" of messages received, a divider line, and then 4 lines for current outgoing message.

When a message comes in, erase old messages, then redraw old messages up higher, then write the new message at its place. Then resume accepting inputs for messages being typed.

You'll want to define functions for writing input on a given line so you can put the text on the line you want it to be on. Another, seemingly easy, option is to use a GUI? Just saying. You provided a link for having multiple console windows, so you obviously know how to do that.

+-------------------------------+
| TOM: Hey man does this work?  |
| TOM: wow you type slow.       |
|                               |
|                               |
|                               |
|                               |
+-------------------------------+
| Yes, it seems to be worki     |
+-------------------------------+

Upvotes: 1

Related Questions