I want to build chat-like application. I have two threads, one for user input and one for printing received messages. When socket receives the message it prints it out but it ruins user input. I want to know if there is any way for print to skip input line.
https://i.stack.imgur.com/5yr3O.jpg
You can see how it removes ">>" when client connects. I just want print and input at the same time without disrupting input.
def listen_clients(self):
while True:
conn, addr = self.sock.accept()
print(clr("[+] Client connected ({}:{})".format(addr[0], addr[1]), "green"))
self.clients.append({
"ip": addr[0],
"port": addr[1],
"conn": conn })
INPUT
def initiate_cli(self):
while True:
command = input(" >> ")
if command == "clients":
for client in self.clients:
print(" {0:3}: {1}: {2:5}".format(self.clients.index(client), client["ip"], client["port"]))