temrinal and commands added

master
Your Name 6 years ago
parent eb2baa377a
commit 6c578da591

@ -7,58 +7,97 @@ from PIL import Image, ImageOps
import curses
import sys, termios, tty, os, time
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class Printer():
ESC = b'\x1B'
CHANGE_EMULATION = ESC+b'\x7B'+b'\x65'
LINE_FEED = b'\n'
CARIDGE_RET = b'\x0D'
CHARWIDTH = 78
strokes = 0
debug = True
target = "/dev/usb/lp0"
if debug:
target = "/dev/tty"
def printchar(self,char):
with open('/dev/usb/lp0', 'wb') as printer:
with open(self.target, 'wb') as printer:
printer.write(self.ESC+b"\x7B"+b"\x41")
char=self.strokes*" "+char
printer.write(bytes(str(char), 'utf-8'))
printer.write(self.ESC+b"\x25"+b"\x46"+b"\x0F"+b"\x00"+b"\x04"+b"\x08"+b"\x00")
self.strokes += 1
if(self.strokes>78):
if(self.strokes>self.CHARWIDTH):
printer.write(self.LINE_FEED)
self.strokes = 0
def printstring(self,string):
with open(self.target, 'wb') as printer:
printer.write(self.ESC+b"\x7B"+b"\x41")
printer.write(bytes(str(string), 'utf-8'))
printer.write(self.ESC+b"\x25"+b"\x46"+b"\x0F"+b"\x00"+b"\x04"+b"\x08"+b"\x00")
self.newline()
def newline(self):
global strokes
with open('/dev/usb/lp0', 'wb') as printer:
with open(self.target, 'wb') as printer:
printer.write(self.LINE_FEED)
self.strokes = 0
def waitforinput():
while True:
char = getch()
if (ord(char) == 27):
print("exited publication :-(")
exit(0)
if (ord(char) == 13):
printer.newline()
else:
printer.printchar(char)
class Terminal():
lineinput = ""
commandMode = False
writeloop = True
def __init__(self,printer):
self.printer = printer
def waitforinput(self):
term.writeloop = True
while self.writeloop:
char = self.getch()
self.lineinput+=char
print(self.lineinput)
if (ord(char) == 27):
print("exit publication :-(")
exit(0)
if (ord(char) == 13):
self.printer.newline()
self.checkforcommand(self.lineinput)
self.lineinput = ""
else:
print(char)
self.printer.printchar(char)
def getch(self):
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
def checkforcommand(self, command):
print("received command:"+command)
if command == "help":
#if the command is valid we want to execute the command and continue the story
#self.writeloop = False
print("POETIC SOFTWARE")
print("Let's boot into this publication together?")
print("cancel [ok]")
printer = Printer()
waitforinput()
term = Terminal(printer)
printer.printstring("W E L C O M E !")
printer.printstring("---------------")
printer.printstring("POETIC SOFTWARE")
printer.printstring("---------------")
printer.printstring("type help for help")
term.waitforinput()
printer.printstring("write a command")
term.waitforinput()

Loading…
Cancel
Save