create screen_utils

This commit is contained in:
chrys 2016-10-29 16:40:34 +02:00
parent 3ec6697b58
commit 5839a8fbcb
2 changed files with 53 additions and 33 deletions

View File

@ -5,6 +5,7 @@
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
from core import debug from core import debug
from collections import Counter
def getPrevLine(currX,currY, currText): def getPrevLine(currX,currY, currText):
if currText == '': if currText == '':
@ -39,36 +40,3 @@ def getNextLine(currX,currY, currText):
x = 0 x = 0
currLine = wrappedLines[y] currLine = wrappedLines[y]
return x, y, currLine return x, y, currLine
#!/bin/python
def insertNewlines(string, every=64):
return '\n'.join(string[i:i+every] for i in range(0, len(string), every))
def splitAtrrLines(string, every=64):
return list(string[i:i+every] for i in range(0, len(string), every))
old = b'das ist ein test'
new = b'das axd ein test'
text = 'das iet ein test'
text = insertNewlines(text,4)
alts = splitAtrrLines(old,4)
neus = splitAtrrLines(new,4)
def trackHighlights(old, new, text):
result = ''
text = text.split('\n')
if len(old) != len(new):
return result
if len(text) != len(new):
return result
for line in range(len(new)):
if old[line] != new[line]:
for column in range(len(new)):
if old[line][column] != new[line][column]:
result += text[line][column]
result += ' '
return result
print(trackHighlights(alts,neus,text))

View File

@ -0,0 +1,52 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
from collections import Counter
def insertNewlines(string, every=64):
return '\n'.join(string[i:i+every] for i in range(0, len(string), every))
def splitAtrrLines(string, every=64):
return list(string[i:i+every] for i in range(0, len(string), every))
old = b'eeeemmmeeeeeeeee'
new = b'eeeeeueeeeeeeeee'
text = 'das ist ein test'
def trackHighlights(oldAttr, newAttr, text):
result = ''
currCursor = None
if oldAttr == newAttr:
return result, currCursor
if len(newAttr) == 0:
return result, currCursor
textLines = insertNewlines(text,4)
textLines = textLines.split('\n')
old = splitAtrrLines(oldAttr,4)
new = splitAtrrLines(newAttr,4)
if len(old) != len(new):
return result, currCursor
if len(text) != len(new):
return result, currCursor
try:
background = Counter(newAttr).most_common(1)
background = background[0][0]
except Exception as e:
background = chr(7)
for line in range(len(new)):
if old[line] != new[line]:
for column in range(len(new)):
if old[line][column] != new[line][column]:
if new[line][column] != background:
if not currCursor:
currCursor['x'] = column
currCursor['y'] = line
result += textLines[line][column]
result += ' '
return result, currCursor
print(trackHighlights(alts,neus,text))