Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ansi escape and readline so output doesnt mix with input in cli #638

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions syncplay/ui/consoleUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import threading
import time
import os
try:
import readline
except ImportError:
pass

import syncplay
from syncplay import constants
Expand All @@ -14,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()
Expand Down Expand Up @@ -105,10 +110,17 @@ def showMessage(self, message, noTimestamp=False):
message = message.decode('utf-8')
except UnicodeEncodeError:
pass
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)
if not self.isWindows:
line = readline.get_line_buffer()
if line != '':
print(line, end='')
sys.stdout.flush()

def showDebugMessage(self, message):
print(message)
Expand Down
Loading