2016-07-04 18:16:22 -04:00
|
|
|
#!/bin/python
|
2016-07-04 18:24:27 -04:00
|
|
|
|
|
|
|
# Fenrir TTY screen reader
|
|
|
|
# By Chrys, Storm Dragon, and contributers.
|
|
|
|
|
2016-07-04 18:16:22 -04:00
|
|
|
import hashlib
|
|
|
|
import difflib
|
|
|
|
import textwrap
|
2016-07-05 15:34:50 -04:00
|
|
|
import speech.es as es
|
2016-07-06 19:07:46 -04:00
|
|
|
import speech.sd as sd
|
2016-07-05 15:34:50 -04:00
|
|
|
|
|
|
|
runtime = {
|
2016-07-05 17:54:11 -04:00
|
|
|
'running':True,
|
2016-07-05 15:34:50 -04:00
|
|
|
'columns': 0,
|
2016-07-05 17:18:03 -04:00
|
|
|
'lines': 0,
|
2016-07-05 19:13:28 -04:00
|
|
|
'screenDriver': '/dev/vcsa',
|
2016-07-05 15:34:50 -04:00
|
|
|
'delta': '',
|
2016-07-05 17:18:03 -04:00
|
|
|
'oldCursor':{'x':0,'y':0},
|
2016-07-05 15:34:50 -04:00
|
|
|
'oldContentBytes': b'',
|
|
|
|
'oldContentText': '',
|
|
|
|
'oldContentAttrib': b'',
|
2016-07-05 17:18:03 -04:00
|
|
|
'newCursor':{'x':0,'y':0},
|
2016-07-05 15:34:50 -04:00
|
|
|
'newContentBytes': b'',
|
|
|
|
'newContentText': '',
|
|
|
|
'newContentAttrib': b'',
|
2016-07-05 19:13:28 -04:00
|
|
|
'oldTTY':'0',
|
|
|
|
'newTTY':'0',
|
2016-07-06 19:13:45 -04:00
|
|
|
'speechDriverString':'es',
|
|
|
|
'speechDriver': es.speech()
|
2016-07-05 15:34:50 -04:00
|
|
|
}
|
2016-07-04 18:16:22 -04:00
|
|
|
|
2016-07-05 17:54:11 -04:00
|
|
|
while(runtime['running']):
|
2016-07-05 17:18:03 -04:00
|
|
|
# read screen
|
2016-07-05 19:13:28 -04:00
|
|
|
currTTY = open('/sys/devices/virtual/tty/tty0/active','r')
|
|
|
|
runtime['newTTY'] = currTTY.read()[3:-1]
|
|
|
|
currTTY.close()
|
|
|
|
runtime['newTTY'] = '3'
|
|
|
|
try:
|
|
|
|
vcsa = open(runtime['screenDriver'] + runtime['newTTY'] ,'rb')
|
|
|
|
runtime['newContentBytes'] = vcsa.read()
|
|
|
|
vcsa.close()
|
|
|
|
except:
|
|
|
|
print(runtime['screenDriver'] + runtime['newTTY'])
|
|
|
|
continue
|
2016-07-05 17:18:03 -04:00
|
|
|
|
|
|
|
# get metadata like cursor or screensize
|
|
|
|
runtime['lines'] = int( runtime['newContentBytes'][0])
|
2016-07-05 15:34:50 -04:00
|
|
|
runtime['columns'] = int( runtime['newContentBytes'][1])
|
2016-07-05 17:18:03 -04:00
|
|
|
runtime['newCursor']['x'] = int( runtime['newContentBytes'][2])
|
|
|
|
runtime['newCursor']['y'] = int( runtime['newContentBytes'][3])
|
|
|
|
|
|
|
|
# analyze content
|
|
|
|
runtime['newContentText'] = str(runtime['newContentBytes'][4:][::2].decode('cp1252').encode('utf-8'))
|
|
|
|
runtime['newContentAttrib'] = runtime['newContentBytes'][5:][::2]
|
2016-07-06 19:12:26 -04:00
|
|
|
runtime['newContentText'] = '\n'.join(textwrap.wrap(runtime['newContentText'], runtime['columns']))[:-1]
|
2016-07-05 19:13:28 -04:00
|
|
|
if runtime['newTTY'] != runtime['oldTTY']:
|
|
|
|
runtime['oldContentBytes'] = b''
|
|
|
|
runtime['oldContentAttrib'] = b''
|
|
|
|
runtime['oldContentText'] = ''
|
|
|
|
runtime['oldCursor']['x'] = 0
|
|
|
|
runtime['oldCursor']['y'] = 0
|
|
|
|
|
2016-07-05 17:18:03 -04:00
|
|
|
# changes on the screen
|
2016-07-05 15:34:50 -04:00
|
|
|
if runtime['oldContentBytes'] != runtime['newContentBytes']:
|
2016-07-05 18:03:26 -04:00
|
|
|
if len(runtime['delta']) < 3:
|
2016-07-05 18:32:06 -04:00
|
|
|
runtime['speechDriver'].cancel()
|
2016-07-05 18:43:04 -04:00
|
|
|
print(len(runtime['delta']))
|
2016-07-04 18:16:22 -04:00
|
|
|
print("tty3 changed")
|
2016-07-05 18:43:04 -04:00
|
|
|
print(runtime['delta'])
|
2016-07-05 15:34:50 -04:00
|
|
|
diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText'])
|
|
|
|
runtime['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
|
2016-07-06 19:12:26 -04:00
|
|
|
print(runtime['delta'])
|
2016-07-05 17:18:03 -04:00
|
|
|
runtime['speechDriver'].speak(runtime['delta'])
|
2016-07-04 18:16:22 -04:00
|
|
|
|
2016-07-05 17:18:03 -04:00
|
|
|
# set new "old" values
|
2016-07-05 15:34:50 -04:00
|
|
|
runtime['oldContentBytes'] = runtime['newContentBytes']
|
|
|
|
runtime['oldContentText'] = runtime['newContentText']
|
|
|
|
runtime['oldContentTextAttrib'] = runtime['newContentAttrib']
|
2016-07-05 17:18:03 -04:00
|
|
|
runtime['oldCursor']['x'] = runtime['newCursor']['x']
|
|
|
|
runtime['oldCursor']['y'] = runtime['newCursor']['y']
|
2016-07-05 19:13:28 -04:00
|
|
|
runtime['oldTTY'] = runtime['newTTY']
|