From 22b5f6b29c920fb5ea7c66fd5ed981ef9bb36839 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Wed, 10 May 2017 17:11:29 +0200 Subject: [PATCH] Create print_escape.py --- play zone/print_escape.py | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 play zone/print_escape.py diff --git a/play zone/print_escape.py b/play zone/print_escape.py new file mode 100644 index 00000000..7ccb1e54 --- /dev/null +++ b/play zone/print_escape.py @@ -0,0 +1,41 @@ +#!/bin/python3 +import sys, os +import pty +import pyte + +class FenrirTermStream(pyte.Stream): + def __init__(self): + super().__init__() + def attach(self, screen): + super().attach(screen) + def feed(self, text): + super().feed(text) + +class FenrirTermEmu(): + def __init__(self): + self.shell = '/bin/bash' + if 'SHELL' in os.environ: + self.shell = os.environ['SHELL'] + self.screen = pyte.Screen(80,24) + self.stream = FenrirTermStream() + self.stream.attach(self.screen) + def outputCallback(self, fd): + data = os.read(fd, 1024) + self.stream.feed(data.decode('UTF8')) + # alles + #print(self.screen.display) + # input + #print(data.decode('UTF8')) + return data + def inputCallback(self, fd): + data = os.read(fd, 1024) + print('|'+str(data)+'|') + if data == b'q': + print('quit') + return b'exit\r' + return data + def startEmulator(self): + pty.spawn(self.shell, self.outputCallback, self.inputCallback) + +t = FenrirTermEmu() +t.startEmulator()