Update ptyDriver.py

This commit is contained in:
chrys87 2018-05-29 15:06:45 +02:00 committed by GitHub
parent 48c44ead7b
commit 9589b05629
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,8 @@ from fenrirscreenreader.utils import screen_utils
class Terminal: class Terminal:
def __init__(self, columns, lines, p_in): def __init__(self, columns, lines, p_in):
self.text = ''
self.attributes = []
self.screen = pyte.HistoryScreen(columns, lines) self.screen = pyte.HistoryScreen(columns, lines)
self.screen.set_mode(pyte.modes.LNM) self.screen.set_mode(pyte.modes.LNM)
self.screen.write_process_input = \ self.screen.write_process_input = \
@ -32,17 +34,17 @@ class Terminal:
yPos = self.screen.cursor.y yPos = self.screen.cursor.y
self.screen.cursor.x = min(self.screen.cursor.x, self.screen.columns - 1) self.screen.cursor.x = min(self.screen.cursor.x, self.screen.columns - 1)
self.screen.cursor.y = min(self.screen.cursor.y, self.screen.lines - 1) self.screen.cursor.y = min(self.screen.cursor.y, self.screen.lines - 1)
def dump(self): def GetScreenContent(self):
cursor = self.screen.cursor cursor = self.screen.cursor
text = '\n'.join(self.screen.display) self.text = '\n'.join(self.screen.display)
buffer = self.screen.buffer buffer = self.screen.buffer
attributes = [[list(attribute[1:]) + [False, 'default', 'default'] for attribute in line.values()] for line in buffer.values()] self.attributes = [[list(attribute[1:]) + [False, 'default', 'default'] for attribute in line.values()] for line in buffer.values()]
self.screen.dirty.clear() self.screen.dirty.clear()
return {"cursor": (cursor.x, cursor.y), return {"cursor": (cursor.x, cursor.y),
'lines': self.screen.lines, 'lines': self.screen.lines,
'columns': self.screen.columns, 'columns': self.screen.columns,
"text": text, "text": self.text,
'attributes': attributes.copy(), 'attributes': self.attributes.copy(),
'screen': 'pty' 'screen': 'pty'
}.copy() }.copy()
@ -156,7 +158,7 @@ class driver(screenDriver):
terminal.feed(msgBytes) terminal.feed(msgBytes)
os.write(sys.stdout.fileno(), msgBytes) os.write(sys.stdout.fileno(), msgBytes)
eventQueue.put({"Type":fenrirEventType.ScreenUpdate, eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
"Data":screen_utils.createScreenEventData(terminal.dump()) "Data":screen_utils.createScreenEventData(terminal.GetScreenContent())
}) })
except Exception as e: # Process died? except Exception as e: # Process died?
print(e) print(e)