Reputation: 1
I'm working on a little bash chat. So I would like to have at the bottom of the window, a line where the user can input his message. When he press "enter" the message is sent and print right above the last line. This line must'n move ! like this
User A sent: xxxx
User B sent: xxxx
User C sent: xxxx
User A sent: xxxx
User B sent: xxxx
Write your message here : YYYY *hit enter*
================================================
User A sent: xxxx
User B sent: xxxx
User C sent: xxxx
User A sent: xxxx
User B sent: xxxx
You: YYYY
Write your message here :
I use read userinput
to get the input but a line break appears when he presses "enter" to send his message.
So I tried this:
echo -e "\033[2A"; #cursor up 2 lines; echo -en "\r$i"; #remove carriage returns;
I wrote "Hello" and "Bye" here's what's going on ! I don't know how to solve the problem. Somebody's got a solution ? Thanks
Helloge: Hello
Byesage: Bye
message:
Upvotes: 0
Views: 157
Reputation: 1
I looked up the slider movements and I changed your code a little bit and got what I wanted.
while true; do
echo -e "message: \c"
read usermess
echo -e "\033[1A\033[1D====> Your message: $usermess"
done
Output:
====> Your message: Hello
====> Your message: Hey
message: Welcome
Thank you for your feedback
Upvotes: 0
Reputation: 48
I advise you take a look into Cursor Movement . What you need is to move the cursor to the right \033[9C
like so:
echo -e "\033[2A\033[9C$var_with_text_here"
If this isn't really what you need, then please explain better and I'll edit my answer :)
Example:
[user@host ~]$ echo "Message: bla"
Message: Hello
[user@host ~]$ echo -e "\033[2A\033[9CHello"
Upvotes: 1