tweak some things

This commit is contained in:
chrys 2016-07-07 17:22:30 +02:00
parent 88d2abc71a
commit ac4e654aa3

View File

@ -6,43 +6,27 @@
import hashlib import hashlib
import difflib import difflib
import textwrap import textwrap
import time
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import utils.debug import utils.debug
import core.environment as environment
import speech.espeak as es import speech.espeak as es
import speech.speechd as sd import speech.speechd as sd
runtime = { runtime = environment.runtime
'running':True, runtime['screenDriver'] = '/dev/vcsa'
'columns': 0, runtime['speechDriverString'] = 'speechd'
'lines': 0, runtime['speechDriver'] = sd.speech()
'screenDriver': '/dev/vcsa',
'delta': '',
'oldCursor':{'x':0,'y':0},
'oldContentBytes': b'',
'oldContentText': '',
'oldContentAttrib': b'',
'newCursor':{'x':0,'y':0},
'newContentBytes': b'',
'newContentText': '',
'newContentAttrib': b'',
'oldTTY':'0',
'newTTY':'0',
'speechDriverString':'speechd',
'speechDriver': sd.speech()
}
while(runtime['running']): while(runtime['running']):
# read screen # read screen
currTTY = open('/sys/devices/virtual/tty/tty0/active','r') currTTY = open('/sys/devices/virtual/tty/tty0/active','r')
runtime['newTTY'] = currTTY.read()[3:-1] runtime['newTTY'] = currTTY.read()[3:-1]
currTTY.close() currTTY.close()
p = Popen("fgconsole", stdout=PIPE, stderr=PIPE, shell=True)
runtime['newTTY'], stderr = p.communicate()
runtime['newTTY'] = str(int(runtime['newTTY']))
#runtime['newTTY'] = str(currTTY)
try: try:
vcsa = open(runtime['screenDriver'] + runtime['newTTY'] ,'rb') vcsa = open(runtime['screenDriver'] + runtime['newTTY'] ,'rb',0)
runtime['newContentBytes'] = vcsa.read() runtime['newContentBytes'] = vcsa.read()
vcsa.close() vcsa.close()
except: except:
@ -55,9 +39,12 @@ while(runtime['running']):
runtime['newCursor']['y'] = int( runtime['newContentBytes'][3]) runtime['newCursor']['y'] = int( runtime['newContentBytes'][3])
# analyze content # analyze content
runtime['newContentText'] = str(runtime['newContentBytes'][4:][::2].decode('cp1252').encode('utf-8'))
runtime['newContentText'] = str(runtime['newContentBytes'][4:][::2].decode('cp1252').encode('utf-8'))[2:-1]
runtime['newContentAttrib'] = runtime['newContentBytes'][5:][::2] runtime['newContentAttrib'] = runtime['newContentBytes'][5:][::2]
runtime['newContentText'] = '\n'.join(textwrap.wrap(runtime['newContentText'], runtime['columns']))[:-1] runtime['newContentText'] = '\n'.join(textwrap.wrap(runtime['newContentText'], runtime['columns']))[:-1]
print("|"+runtime['newContentText'] +"|")
print(runtime['newTTY'])
if runtime['newTTY'] != runtime['oldTTY']: if runtime['newTTY'] != runtime['oldTTY']:
runtime['oldContentBytes'] = b'' runtime['oldContentBytes'] = b''
runtime['oldContentAttrib'] = b'' runtime['oldContentAttrib'] = b''