I'm currently working on a chat application with Python, but am currently facing an annoying problem. When the user is inputting a message to the console, while an another user is sending messages, the input message of the first user gets split into multiple lines. I attached a picture of the problem.
As you can see, the input is being intercepted with the output of the console.
For the input, I was holding down Z while a friend was sending messages to the channel. As you can see, It's being interrupted by the messages that are appearing.
Edit:
import colorama
from termcolor import cprint
colorama.init()
green = '\33[92m'
reset = '\033[0m'
def receive_messages():
while True:
data = s.recv(1024).decode()
#s is a previously defined socket
ind = data.index(">") + 1
usr = data[:ind]
raw = data[ind:]
cprint(green + usr + green + reset + raw + reset)
threading.Thread(target = receive_messages).start()
username = #opens the file where the username is stored: <username>
while True:
txt = input()
s.send((username + " " + txt).encode())
What I want is the input text to be locked in one line and not split into many.