Update client.py

This commit is contained in:
2026-02-21 14:37:14 +01:00
parent 791363810d
commit f277edfd9b

View File

@@ -67,7 +67,7 @@ def recv_json(sock):
return json.loads(buffer.decode("utf-8")) return json.loads(buffer.decode("utf-8"))
except json.JSONDecodeError: except json.JSONDecodeError:
continue continue
return {} # fallback, lege dict als niks lukt return {}
def login(): def login():
base_dir = Path(__file__).parent base_dir = Path(__file__).parent
@@ -140,6 +140,8 @@ chat_data = recv_json(s)
chat_names = list(chat_data.keys()) chat_names = list(chat_data.keys())
def draw_chat_window(messages, chatname): def draw_chat_window(messages, chatname):
current_input = readline.get_line_buffer() # bewaar wat je typt
clear() clear()
w, h = term_size() w, h = term_size()
print(blauw_bg + wit + chatname.center(w) + reset) print(blauw_bg + wit + chatname.center(w) + reset)
@@ -154,6 +156,9 @@ def draw_chat_window(messages, chatname):
print_white(f"[{user}] {text}") print_white(f"[{user}] {text}")
print("-" * w) print("-" * w)
readline.insert_text(current_input) # herstel input
readline.redisplay()
def chat_session(chatkeuze): def chat_session(chatkeuze):
global chat_messages, chat_users global chat_messages, chat_users
s.sendall(json.dumps({"action": "openchat", "chat_name": chatkeuze}).encode("utf-8")) s.sendall(json.dumps({"action": "openchat", "chat_name": chatkeuze}).encode("utf-8"))