From 0cf00ffea3b7c7924aae452c6217ff062c3fcea0 Mon Sep 17 00:00:00 2001 From: Mark Olsson Date: Wed, 20 May 2020 12:21:58 +0200 Subject: [PATCH] Fixes Mu-Terminal utf-8 encoding. Fixes #759 --- mu/interface/panes.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mu/interface/panes.py b/mu/interface/panes.py index 09ed033f3..189932907 100644 --- a/mu/interface/panes.py +++ b/mu/interface/panes.py @@ -251,17 +251,22 @@ def process_bytes(self, data): while tc.movePosition(QTextCursor.Down): pass i = 0 + data = data.decode("utf-8") while i < len(data): - if data[i] == 8: # \b + if ord(data[i]) == 8: # \b tc.movePosition(QTextCursor.Left) self.setTextCursor(tc) - elif data[i] == 13: # \r + elif ord(data[i]) == 13: # \r pass - elif len(data) > i + 1 and data[i] == 27 and data[i + 1] == 91: + elif ( + len(data) > i + 1 + and ord(data[i]) == 27 + and ord(data[i + 1]) == 91 + ): # VT100 cursor detected: [ i += 2 # move index to after the [ regex = r"(?P[\d]*)(;?[\d]*)*(?P[ABCDKm])" - m = re.search(regex, data[i:].decode("utf-8")) + m = re.search(regex, data[i:]) if m: # move to (almost) after control seq # (will ++ at end of loop) @@ -292,14 +297,14 @@ def process_bytes(self, data): ) tc.removeSelectedText() self.setTextCursor(tc) - elif data[i] == 10: # \n + elif ord(data[i]) == 10: # \n tc.movePosition(QTextCursor.End) self.setTextCursor(tc) - self.insertPlainText(chr(data[i])) + self.insertPlainText(data[i]) else: tc.deleteChar() self.setTextCursor(tc) - self.insertPlainText(chr(data[i])) + self.insertPlainText(data[i]) i += 1 self.ensureCursorVisible()