From 18a4383eadb7ef50703829b5124f1a3b6a25f57c Mon Sep 17 00:00:00 2001 From: chrys87 Date: Fri, 28 Apr 2017 14:16:36 +0200 Subject: [PATCH] initial python terminal emulator for PTY driver --- play zone/pya.py | 24 ------------------------ play zone/pyterm.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 24 deletions(-) delete mode 100755 play zone/pya.py create mode 100755 play zone/pyterm.py diff --git a/play zone/pya.py b/play zone/pya.py deleted file mode 100755 index f72d85e6..00000000 --- a/play zone/pya.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/python3 -import sys, os -import pty - -mode = 'wb' -shell = '/bin/bash' -if 'SHELL' in os.environ: - shell = os.environ['SHELL'] - -filename = '/home/chrys/mytypescript.txt' - -script = open(filename, mode) - -def read(fd): - data = os.read(fd, 1024) - script.write(data) - return data - -def write(fd): - data = os.read(fd, 1024) - return data - -pty.spawn(shell, read, write) - diff --git a/play zone/pyterm.py b/play zone/pyterm.py new file mode 100755 index 00000000..7be1844a --- /dev/null +++ b/play zone/pyterm.py @@ -0,0 +1,34 @@ +#!/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) + return data + def startEmulator(self): + pty.spawn(self.shell, self.outputCallback, self.inputCallback)