1

I'm trying to make a chat program in Bash.
I've stumbled into a problem though: I have no idea how to have the input and output on the same screen.
What I mean by this is something like the Minecraft server console: the output displays at the top of the screen, and the bottom line of the program is a prompt to enter strings. The output never crosses over the bottom line of the program.
To accomplish this, I think I need to accomplish three things:
- 1 Somehow manage to run two tasks at once
- 2 Somehow manage to make these two tasks run in the same window
- 3 Somehow manage to keep the two tasks in invisible "boxes", that the output can't escape out of (for example, the "box" for the output would start from the top of the window and would end on the last line before the input)

How do I accomplish all of these?

4
  • 1) The unix kernel can run lots of processes. Perhaps you could use one process for each direction? 2) If you do use 2 processes, and one is the child of the other then they will start with the same file descriptors. 3) If you restrict yourself to a vt220/xterm type system then there are escape sequences which save and restore the cursor position, query the position. There is also the concept of scrolling region which can give you your boxes. So you could set up a scrolling region and read a line and print it to a fifo or file in one process, and in a second you could read the file ... cont Commented Nov 20, 2016 at 5:58
  • using tail -f. Each time tail gave you something you could output the codes to save the cursor, change the scrolling region to the "output box", move the cursor to the bottom of the output box, output what you got from tail, change the scrolling region back to the input box, and restore the cursor. Not 100% foolproof, as someone typing whilst stuff is being output might end up in the wrong box, but not much with the speed of modern machines. The original cu program used 2 processes. Commented Nov 20, 2016 at 6:05
  • The simplest way is going to be to use something like tmux. Commented Nov 20, 2016 at 7:23
  • 1
    The simplest is going to be use talk. Commented Nov 21, 2016 at 0:11

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.