From 9d319b74604cfae1b150a5e5a50182d96ce54812 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Thu, 11 Jan 2024 16:11:08 -0500 Subject: [PATCH] Fix unicode chars in terminal w/ texitiowrapper --- app/classes/shared/server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 8448f656..48816d1c 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -1,5 +1,6 @@ from contextlib import redirect_stderr import os +import io import re import shutil import time @@ -115,14 +116,17 @@ class ServerOutBuf: ServerOutBuf.lines[self.server_id].pop(0) def check(self): + text_wrapper = io.TextIOWrapper( + self.proc.stdout, encoding="UTF-8", errors="ignore", newline="" + ) while True: if self.proc.poll() is None: - char = self.proc.stdout.read(1).decode("utf-8", "ignore") + char = text_wrapper.read(1) # modified # TODO: we may want to benchmark reading in blocks and userspace # processing it later, reads are kind of expensive as a syscall self.process_byte(char) else: - flush = self.proc.stdout.read().decode("utf-8", "ignore") + flush = text_wrapper.read() # modified for char in flush: self.process_byte(char) break