fix formatting
This commit is contained in:
parent
ac4e654aa3
commit
a7af5fadde
@ -7,7 +7,6 @@ import hashlib
|
|||||||
import difflib
|
import difflib
|
||||||
import textwrap
|
import textwrap
|
||||||
import time
|
import time
|
||||||
from subprocess import Popen, PIPE
|
|
||||||
|
|
||||||
import utils.debug
|
import utils.debug
|
||||||
import core.environment as environment
|
import core.environment as environment
|
||||||
@ -20,50 +19,50 @@ runtime['speechDriverString'] = 'speechd'
|
|||||||
runtime['speechDriver'] = sd.speech()
|
runtime['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()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vcsa = open(runtime['screenDriver'] + runtime['newTTY'] ,'rb',0)
|
vcsa = open(runtime['screenDriver'] + runtime['newTTY'] ,'rb',0)
|
||||||
runtime['newContentBytes'] = vcsa.read()
|
runtime['newContentBytes'] = vcsa.read()
|
||||||
vcsa.close()
|
vcsa.close()
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# get metadata like cursor or screensize
|
# get metadata like cursor or screensize
|
||||||
runtime['lines'] = int( runtime['newContentBytes'][0])
|
runtime['lines'] = int( runtime['newContentBytes'][0])
|
||||||
runtime['columns'] = int( runtime['newContentBytes'][1])
|
runtime['columns'] = int( runtime['newContentBytes'][1])
|
||||||
runtime['newCursor']['x'] = int( runtime['newContentBytes'][2])
|
runtime['newCursor']['x'] = int( runtime['newContentBytes'][2])
|
||||||
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'))[2:-1]
|
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['newContentText'] +"|")
|
||||||
print(runtime['newTTY'])
|
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''
|
||||||
runtime['oldContentText'] = ''
|
runtime['oldContentText'] = ''
|
||||||
runtime['oldCursor']['x'] = 0
|
runtime['oldCursor']['x'] = 0
|
||||||
runtime['oldCursor']['y'] = 0
|
runtime['oldCursor']['y'] = 0
|
||||||
|
|
||||||
# changes on the screen
|
# changes on the screen
|
||||||
if runtime['oldContentBytes'] != runtime['newContentBytes']:
|
if runtime['oldContentBytes'] != runtime['newContentBytes']:
|
||||||
if ((len(runtime['delta']) < 3) or runtime['oldTTY'] != runtime['newTTY']):
|
if ((len(runtime['delta']) < 3) or runtime['oldTTY'] != runtime['newTTY']):
|
||||||
runtime['speechDriver'].cancel()
|
runtime['speechDriver'].cancel()
|
||||||
diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText'])
|
diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText'])
|
||||||
runtime['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
|
runtime['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
|
||||||
runtime['speechDriver'].speak(runtime['delta'])
|
runtime['speechDriver'].speak(runtime['delta'])
|
||||||
|
|
||||||
# set new "old" values
|
# set new "old" values
|
||||||
runtime['oldContentBytes'] = runtime['newContentBytes']
|
runtime['oldContentBytes'] = runtime['newContentBytes']
|
||||||
runtime['oldContentText'] = runtime['newContentText']
|
runtime['oldContentText'] = runtime['newContentText']
|
||||||
runtime['oldContentTextAttrib'] = runtime['newContentAttrib']
|
runtime['oldContentTextAttrib'] = runtime['newContentAttrib']
|
||||||
runtime['oldCursor']['x'] = runtime['newCursor']['x']
|
runtime['oldCursor']['x'] = runtime['newCursor']['x']
|
||||||
runtime['oldCursor']['y'] = runtime['newCursor']['y']
|
runtime['oldCursor']['y'] = runtime['newCursor']['y']
|
||||||
runtime['oldTTY'] = runtime['newTTY']
|
runtime['oldTTY'] = runtime['newTTY']
|
||||||
|
Loading…
Reference in New Issue
Block a user