diff --git a/src/fenrir/utils/line_utils.py b/src/fenrir/utils/line_utils.py index 21088b56..7b16717e 100644 --- a/src/fenrir/utils/line_utils.py +++ b/src/fenrir/utils/line_utils.py @@ -5,6 +5,7 @@ # By Chrys, Storm Dragon, and contributers. from core import debug +from collections import Counter def getPrevLine(currX,currY, currText): if currText == '': @@ -39,36 +40,3 @@ def getNextLine(currX,currY, currText): x = 0 currLine = wrappedLines[y] 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)) diff --git a/src/fenrir/utils/screen_utils.py b/src/fenrir/utils/screen_utils.py new file mode 100644 index 00000000..bb9504c7 --- /dev/null +++ b/src/fenrir/utils/screen_utils.py @@ -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))