From a82cfded8c07753be125f69d2c600904c4da278a Mon Sep 17 00:00:00 2001 From: gospodin Date: Sun, 15 Oct 2023 22:59:13 +0300 Subject: [PATCH] do not use ansi escape codes and readline if on windows --- syncplay/ui/consoleUI.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/syncplay/ui/consoleUI.py b/syncplay/ui/consoleUI.py index 97c4abb..21ec493 100755 --- a/syncplay/ui/consoleUI.py +++ b/syncplay/ui/consoleUI.py @@ -4,7 +4,10 @@ import sys import threading import time import os -import readline +try: + import readline +except ImportError: + pass import syncplay from syncplay import constants @@ -15,6 +18,7 @@ from syncplay.utils import formatTime, isURL class ConsoleUI(threading.Thread): def __init__(self): + self.isWindows = sys.platform.startswith(constants.OS_WINDOWS) self.promptMode = threading.Event() self.PromptResult = "" self.promptMode.set() @@ -106,15 +110,17 @@ class ConsoleUI(threading.Thread): message = message.decode('utf-8') except UnicodeEncodeError: pass - sys.stdout.write('\33[2K\r') + if not self.isWindows: + sys.stdout.write('\33[2K\r') if noTimestamp: print(message) else: print(time.strftime(constants.UI_TIME_FORMAT, time.localtime()) + message) - line = readline.get_line_buffer() - if line != '': - print(line, end='') - sys.stdout.flush() + if not self.isWindows: + line = readline.get_line_buffer() + if line != '': + print(line, end='') + sys.stdout.flush() def showDebugMessage(self, message): print(message)