From f1c675721c03646f16659790a4f6f7531f28739d Mon Sep 17 00:00:00 2001 From: gospodin Date: Sat, 14 Oct 2023 23:45:09 +0300 Subject: [PATCH 1/4] use ansi escape and readline so output doesnt mix with input in cli ui --- syncplay/ui/consoleUI.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/syncplay/ui/consoleUI.py b/syncplay/ui/consoleUI.py index 5ea981978..97c4abb38 100755 --- a/syncplay/ui/consoleUI.py +++ b/syncplay/ui/consoleUI.py @@ -4,6 +4,7 @@ import threading import time import os +import readline import syncplay from syncplay import constants @@ -105,10 +106,15 @@ def showMessage(self, message, noTimestamp=False): message = message.decode('utf-8') except UnicodeEncodeError: pass + 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() def showDebugMessage(self, message): print(message) From fd2142285ad25de242e3ca046ae6a54c70b0f6c8 Mon Sep 17 00:00:00 2001 From: gospodin55 <63956324+gospodin55@users.noreply.github.com> Date: Sun, 15 Oct 2023 21:52:18 +0300 Subject: [PATCH 2/4] Added readline to buildPy2exe.py --- buildPy2exe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildPy2exe.py b/buildPy2exe.py index 22a4f0257..2044eb9ea 100755 --- a/buildPy2exe.py +++ b/buildPy2exe.py @@ -679,7 +679,7 @@ def run(self): 'py2exe': { 'dist_dir': OUT_DIR, 'packages': 'PySide2, cffi, OpenSSL, certifi', - 'includes': 'twisted, sys, encodings, datetime, os, time, math, urllib, ast, unicodedata, _ssl, win32pipe, win32file, sqlite3', + 'includes': 'twisted, sys, encodings, datetime, os, time, math, urllib, ast, unicodedata, _ssl, win32pipe, win32file, sqlite3, readline', 'excludes': 'venv, doctest, pdb, unittest, win32clipboard, win32pdh, win32security, win32trace, win32ui, winxpgui, win32process, tcl, tkinter', 'dll_excludes': 'msvcr71.dll, MSVCP90.dll, POWRPROF.dll', 'optimize': 2, From 109303f136c9d1175c0bf142a5d84cb98599ca66 Mon Sep 17 00:00:00 2001 From: gospodin Date: Sun, 15 Oct 2023 22:35:19 +0300 Subject: [PATCH 3/4] Revert "Added readline to buildPy2exe.py" This reverts commit fd2142285ad25de242e3ca046ae6a54c70b0f6c8. --- buildPy2exe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildPy2exe.py b/buildPy2exe.py index 2044eb9ea..22a4f0257 100755 --- a/buildPy2exe.py +++ b/buildPy2exe.py @@ -679,7 +679,7 @@ def run(self): 'py2exe': { 'dist_dir': OUT_DIR, 'packages': 'PySide2, cffi, OpenSSL, certifi', - 'includes': 'twisted, sys, encodings, datetime, os, time, math, urllib, ast, unicodedata, _ssl, win32pipe, win32file, sqlite3, readline', + 'includes': 'twisted, sys, encodings, datetime, os, time, math, urllib, ast, unicodedata, _ssl, win32pipe, win32file, sqlite3', 'excludes': 'venv, doctest, pdb, unittest, win32clipboard, win32pdh, win32security, win32trace, win32ui, winxpgui, win32process, tcl, tkinter', 'dll_excludes': 'msvcr71.dll, MSVCP90.dll, POWRPROF.dll', 'optimize': 2, From a82cfded8c07753be125f69d2c600904c4da278a Mon Sep 17 00:00:00 2001 From: gospodin Date: Sun, 15 Oct 2023 22:59:13 +0300 Subject: [PATCH 4/4] 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 97c4abb38..21ec49326 100755 --- a/syncplay/ui/consoleUI.py +++ b/syncplay/ui/consoleUI.py @@ -4,7 +4,10 @@ import threading import time import os -import readline +try: + import readline +except ImportError: + pass import syncplay from syncplay import constants @@ -15,6 +18,7 @@ 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 @@ def showMessage(self, message, noTimestamp=False): 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)