2016-12-14 17:05:34 -05:00
|
|
|
#!/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Fenrir TTY screen reader
|
|
|
|
# By Chrys, Storm Dragon, and contributers.
|
|
|
|
|
2018-03-21 06:10:12 -04:00
|
|
|
#from fenrirscreenreader.core import debug
|
2016-12-14 17:35:16 -05:00
|
|
|
import string
|
2016-12-14 17:05:34 -05:00
|
|
|
# X Y Word END BREAK
|
|
|
|
# -1, -1, '', True False
|
|
|
|
def getPrevWord(currX,currY, currText):
|
|
|
|
lineBreak = False
|
|
|
|
endOfScreen = False
|
|
|
|
if currText == '':
|
|
|
|
return -1, -1, '', endOfScreen, lineBreak
|
2016-12-20 10:26:19 -05:00
|
|
|
if currText.strip( string.whitespace) == '':
|
2016-12-14 17:35:16 -05:00
|
|
|
return currX, currY, '', endOfScreen, lineBreak
|
2016-12-19 09:21:00 -05:00
|
|
|
x, y, currWord, endOfScreen, lineBreakCurrWord = getCurrentWord(currX,currY,currText)
|
2016-12-14 17:05:34 -05:00
|
|
|
if endOfScreen:
|
|
|
|
return x, y, currWord, endOfScreen, lineBreak
|
2016-12-14 17:35:16 -05:00
|
|
|
wrappedLines = currText.split('\n')
|
|
|
|
currLine = wrappedLines[y]
|
2016-12-19 09:21:00 -05:00
|
|
|
if x - 1 < 0:
|
|
|
|
if y - 1 < 0:
|
|
|
|
lineBreak = False
|
|
|
|
endOfScreen = True
|
|
|
|
return currX, currY, '', endOfScreen, lineBreak
|
|
|
|
else:
|
|
|
|
y -= 1
|
|
|
|
currLine = wrappedLines[y]
|
|
|
|
x = len( wrappedLines[y]) - 1
|
|
|
|
lineBreak = True
|
|
|
|
else:
|
|
|
|
x -= 1
|
2016-12-19 10:04:21 -05:00
|
|
|
lineBreakCurrWord = lineBreak or lineBreakCurrWord
|
|
|
|
x, y, currWord, endOfScreen, lineBreak = getCurrentWord(x,y,currText)
|
2016-12-19 09:21:00 -05:00
|
|
|
lineBreak = lineBreak or lineBreakCurrWord
|
|
|
|
return x, y, currWord, endOfScreen, lineBreak
|
2016-12-14 17:05:34 -05:00
|
|
|
|
|
|
|
def getCurrentWord(currX,currY, currText):
|
|
|
|
lineBreak = False
|
|
|
|
endOfScreen = False
|
|
|
|
if currText == '':
|
|
|
|
return -1, -1, '', endOfScreen, lineBreak
|
2016-12-20 10:26:19 -05:00
|
|
|
if currText.strip( string.whitespace) == '':
|
2016-12-14 17:35:16 -05:00
|
|
|
return currX, currY, '', endOfScreen, lineBreak
|
2016-12-14 17:05:34 -05:00
|
|
|
x = currX
|
|
|
|
y = currY
|
|
|
|
currWord = ''
|
|
|
|
wrappedLines = currText.split('\n')
|
2016-12-14 17:35:16 -05:00
|
|
|
currLine = wrappedLines[y]
|
|
|
|
Found = False
|
|
|
|
while(not Found):
|
2016-12-19 09:21:00 -05:00
|
|
|
if not currLine[x] in string.whitespace:
|
|
|
|
if x == 0:
|
|
|
|
Found = True
|
|
|
|
else:
|
|
|
|
if currLine[x - 1] in string.whitespace:
|
|
|
|
Found = True
|
|
|
|
if not Found:
|
|
|
|
if x - 1 < 0:
|
|
|
|
if y - 1 < 0:
|
|
|
|
lineBreak = False
|
|
|
|
endOfScreen = True
|
|
|
|
return currX, currY, '', endOfScreen, lineBreak
|
|
|
|
else:
|
|
|
|
y -= 1
|
|
|
|
currLine = wrappedLines[y]
|
|
|
|
x = len( wrappedLines[y]) - 1
|
|
|
|
lineBreak = True
|
|
|
|
else:
|
|
|
|
x -= 1
|
|
|
|
if Found:
|
|
|
|
currWord = currLine[x:]
|
|
|
|
for d in string.whitespace:
|
|
|
|
delimiterPos = currWord.find(d)
|
|
|
|
if delimiterPos != -1:
|
2016-12-19 10:04:21 -05:00
|
|
|
currWord = currWord[:delimiterPos]
|
|
|
|
|
2016-12-14 17:35:16 -05:00
|
|
|
return x, y, currWord, endOfScreen, lineBreak
|
|
|
|
return currX, currY, '', False, False
|
2016-12-14 17:05:34 -05:00
|
|
|
|
|
|
|
def getNextWord(currX,currY, currText):
|
2016-12-19 10:04:21 -05:00
|
|
|
lineBreak = False
|
2016-12-14 17:05:34 -05:00
|
|
|
endOfScreen = False
|
|
|
|
if currText == '':
|
|
|
|
return -1, -1, '', endOfScreen, lineBreak
|
2016-12-20 10:26:19 -05:00
|
|
|
if currText.strip( string.whitespace) == '':
|
2016-12-19 10:04:21 -05:00
|
|
|
return currX, currY, '', endOfScreen, lineBreak
|
|
|
|
x = currX
|
|
|
|
y = currY
|
|
|
|
currWord = ''
|
2016-12-14 17:05:34 -05:00
|
|
|
wrappedLines = currText.split('\n')
|
2016-12-14 17:35:16 -05:00
|
|
|
currLine = wrappedLines[y]
|
|
|
|
Found = False
|
|
|
|
while(not Found):
|
2016-12-19 10:04:21 -05:00
|
|
|
if not Found:
|
|
|
|
if x + 1 > len( currLine ) - 1:
|
|
|
|
if y + 1 > len( wrappedLines ) - 1:
|
|
|
|
lineBreak = False
|
|
|
|
endOfScreen = True
|
|
|
|
return currX, currY, '', endOfScreen, lineBreak
|
|
|
|
else:
|
|
|
|
y += 1
|
|
|
|
currLine = wrappedLines[y]
|
|
|
|
x = 0
|
|
|
|
lineBreak = True
|
|
|
|
else:
|
|
|
|
x += 1
|
|
|
|
if not currLine[x] in string.whitespace:
|
|
|
|
if x == 0:
|
|
|
|
Found = True
|
|
|
|
else:
|
|
|
|
if currLine[x - 1] in string.whitespace:
|
|
|
|
Found = True
|
|
|
|
if Found:
|
|
|
|
currWord = currLine[x:]
|
|
|
|
for d in string.whitespace:
|
|
|
|
delimiterPos = currWord.find(d)
|
|
|
|
if delimiterPos != -1:
|
|
|
|
currWord = currWord[:delimiterPos]
|
2016-12-14 17:35:16 -05:00
|
|
|
return x, y, currWord, endOfScreen, lineBreak
|
|
|
|
return currX, currY, '', False, False
|
|
|
|
|
2016-12-19 10:04:21 -05:00
|
|
|
|
2016-12-14 17:05:34 -05:00
|
|
|
|
2016-12-14 17:35:16 -05:00
|
|
|
data = """das ist ein test lol
|
|
|
|
das ist ein test l
|
|
|
|
das ist ein test
|
|
|
|
|
|
|
|
asdf asdf a
|
|
|
|
test test
|
|
|
|
te test"""
|
|
|
|
print('__DATA START__')
|
|
|
|
print(data)
|
|
|
|
print('__DATA END__\n\n')
|
|
|
|
|
2016-12-19 09:21:00 -05:00
|
|
|
x = 3
|
2016-12-14 17:35:16 -05:00
|
|
|
y = 0
|
|
|
|
x, y, currWord, endOfScreen, lineBreak = getCurrentWord(x,y,data)
|
|
|
|
print(x,y,currWord)
|
2016-12-19 10:04:21 -05:00
|
|
|
|