diff --git a/config/settings/settings.cfg b/config/settings/settings.cfg index fe9283e1..94f08f7d 100644 --- a/config/settings/settings.cfg +++ b/config/settings/settings.cfg @@ -1,4 +1,3 @@ - [sound] enabled=False, driver=sox @@ -29,4 +28,3 @@ wordEcho=True [general] debugLevel=0 punctuationLevel=1 - diff --git a/src/fenrir-package/commands/commands/curr_char.py b/src/fenrir-package/commands/commands/curr_char.py new file mode 100644 index 00000000..d961f476 --- /dev/null +++ b/src/fenrir-package/commands/commands/curr_char.py @@ -0,0 +1,24 @@ +#!/bin/python +from utils import char_utils + +class command(): + def __init__(self): + pass + def run(self, environment): + environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] + if (environment['screenData']['newCursorReview']['y'] == -1) or \ + (environment['screenData']['newCursorReview']['x'] == -1): + environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() + + environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \ + char_utils.getCurrentChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) + + if currChar.strip(" \t\n") == '': + environment['runtime']['outputManager'].presentText(environment, "blank") + else: + environment['runtime']['outputManager'].presentText(environment, currChar) + return environment + def setCallback(self, callback): + pass + def shutdown(self): + pass diff --git a/src/fenrir-package/commands/commands/curr_line.py b/src/fenrir-package/commands/commands/curr_line.py index 3ef8f835..63a47d72 100644 --- a/src/fenrir-package/commands/commands/curr_line.py +++ b/src/fenrir-package/commands/commands/curr_line.py @@ -1,17 +1,22 @@ #!/bin/python +from utils import line_utils class command(): def __init__(self): pass def run(self, environment): environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] - if environment['screenData']['newCursorReview']['y'] == -1: + if (environment['screenData']['newCursorReview']['y'] == -1) or \ + (environment['screenData']['newCursorReview']['x'] == -1): environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() - wrappedLines = environment['screenData']['newContentText'].split('\n') - if wrappedLines[environment['screenData']['newCursorReview']['y']].strip(" \t\n") == '': + + environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \ + line_utils.getCurrentLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) + + if currLine.strip(" \t\n") == '': environment['runtime']['outputManager'].presentText(environment, "blank") else: - environment['runtime']['outputManager'].presentText(environment, wrappedLines[environment['screenData']['newCursorReview']['y']]) + environment['runtime']['outputManager'].presentText(environment, currLine) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/curr_word.py b/src/fenrir-package/commands/commands/curr_word.py index 6a2eb508..a25d5fbf 100644 --- a/src/fenrir-package/commands/commands/curr_word.py +++ b/src/fenrir-package/commands/commands/curr_word.py @@ -1,44 +1,23 @@ #!/bin/python +from utils import word_utils class command(): def __init__(self): pass def run(self, environment): environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] - if environment['screenData']['newCursorReview']['y'] == -1: + if (environment['screenData']['newCursorReview']['y'] == -1) or \ + (environment['screenData']['newCursorReview']['x'] == -1): environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() - wrappedLines = environment['screenData']['newContentText'].split('\n') - currWord = '' - currY = environment['screenData']['newCursorReview']['y'] - currX = environment['screenData']['newCursorReview']['x'] - wordFound = False - while not wordFound: - currLine = wrappedLines[currY].replace("\t"," ") - currX = currLine[:currX + 1].rfind(" ") + 1 - if currX == -1: - currX = 0 - wordEnd = currLine[currX + 1:].find(" ") + currX + 1 - if wordEnd == -1: - wordEnd = len(currLine) -1 - currWord = currLine[currX:wordEnd] - wordFound = currWord.strip(" \t\n") != '' - if not wordFound: - if currX == 0: - if currY != 0: - currY -= 1 - else: - break - currX = len(wrappedLines[currY]) - 1 - else: - currX -= 1 - environment['screenData']['newCursorReview']['y'] = currY - environment['screenData']['newCursorReview']['x'] = currX - - if not wordFound: + + environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \ + word_utils.getCurrentWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) + + if currWord.strip(" \t\n") == '': environment['runtime']['outputManager'].presentText(environment, "blank") else: environment['runtime']['outputManager'].presentText(environment, currWord) - return environment + return environment def setCallback(self, callback): pass def shutdown(self): diff --git a/src/fenrir-package/commands/commands/next_char.py b/src/fenrir-package/commands/commands/next_char.py new file mode 100644 index 00000000..80f7947c --- /dev/null +++ b/src/fenrir-package/commands/commands/next_char.py @@ -0,0 +1,24 @@ +#!/bin/python +from utils import char_utils + +class command(): + def __init__(self): + pass + def run(self, environment): + environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] + if (environment['screenData']['newCursorReview']['y'] == -1) or \ + (environment['screenData']['newCursorReview']['x'] == -1): + environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() + + environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \ + char_utils.getNextChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) + + if currChar.strip(" \t\n") == '': + environment['runtime']['outputManager'].presentText(environment, "blank") + else: + environment['runtime']['outputManager'].presentText(environment, currChar) + return environment + def setCallback(self, callback): + pass + def shutdown(self): + pass diff --git a/src/fenrir-package/commands/commands/next_line.py b/src/fenrir-package/commands/commands/next_line.py index 90ca588f..80f98d85 100644 --- a/src/fenrir-package/commands/commands/next_line.py +++ b/src/fenrir-package/commands/commands/next_line.py @@ -1,19 +1,22 @@ #!/bin/python +from utils import line_utils class command(): def __init__(self): pass def run(self, environment): environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] - if environment['screenData']['newCursorReview']['y'] == -1: + if (environment['screenData']['newCursorReview']['y'] == -1) or \ + (environment['screenData']['newCursorReview']['x'] == -1): environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() - if environment['screenData']['newCursorReview']['y'] + 1 < environment['screenData']['lines']: - environment['screenData']['newCursorReview']['y'] = environment['screenData']['newCursorReview']['y'] + 1 - wrappedLines = environment['screenData']['newContentText'].split('\n') - if wrappedLines[environment['screenData']['newCursorReview']['y']].strip(" \t\n") == '': + + environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \ + line_utils.getNextLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) + + if currLine.strip(" \t\n") == '': environment['runtime']['outputManager'].presentText(environment, "blank") else: - environment['runtime']['outputManager'].presentText(environment, wrappedLines[environment['screenData']['newCursorReview']['y']]) + environment['runtime']['outputManager'].presentText(environment, currLine) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/next_word.py b/src/fenrir-package/commands/commands/next_word.py index 54dd2c4e..65e5cadb 100644 --- a/src/fenrir-package/commands/commands/next_word.py +++ b/src/fenrir-package/commands/commands/next_word.py @@ -1,52 +1,23 @@ #!/bin/python +from utils import word_utils class command(): def __init__(self): pass def run(self, environment): environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] - if environment['screenData']['newCursorReview']['y'] == -1: + if (environment['screenData']['newCursorReview']['y'] == -1) or \ + (environment['screenData']['newCursorReview']['x'] == -1): environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() - wrappedLines = environment['screenData']['newContentText'].split('\n') - currWord = '' - currY = environment['screenData']['newCursorReview']['y'] - currX = environment['screenData']['newCursorReview']['x'] - wordFound = False - currLine = wrappedLines[currY].replace("\t"," ") - while not wordFound: - print(currX) - currX = currLine[currX:].find(" ") + currX - print(currX) - if currX == - 1: - if currY < environment['screenData']['lines']: - currY += 1 - currLine = wrappedLines[currY].replace("\t"," ") - print('erhöhung') - else: - break - currX = 0 - print('hmm') - print(currX) - wordEnd = currLine[currX + 1:].find(" ") - print(currX) - if wordEnd == -1: - wordEnd = len(currLine) - else: - wordEnd += currX + 2 - print(currX) - currWord = currLine[currX:wordEnd] - print(currX) - print(currWord) - wordFound = currWord.strip(" \t\n") != '' - print(wordFound) - environment['screenData']['newCursorReview']['y'] = currY - environment['screenData']['newCursorReview']['x'] = currX - - if not wordFound: + + environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \ + word_utils.getNextWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) + + if currWord.strip(" \t\n") == '': environment['runtime']['outputManager'].presentText(environment, "blank") else: environment['runtime']['outputManager'].presentText(environment, currWord) - return environment + return environment def setCallback(self, callback): pass def shutdown(self): diff --git a/src/fenrir-package/commands/commands/prev_char.py b/src/fenrir-package/commands/commands/prev_char.py new file mode 100644 index 00000000..8bd49d37 --- /dev/null +++ b/src/fenrir-package/commands/commands/prev_char.py @@ -0,0 +1,24 @@ +#!/bin/python +from utils import char_utils + +class command(): + def __init__(self): + pass + def run(self, environment): + environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] + if (environment['screenData']['newCursorReview']['y'] == -1) or \ + (environment['screenData']['newCursorReview']['x'] == -1): + environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() + + environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \ + char_utils.getPrevChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) + + if currChar.strip(" \t\n") == '': + environment['runtime']['outputManager'].presentText(environment, "blank") + else: + environment['runtime']['outputManager'].presentText(environment, currChar) + return environment + def setCallback(self, callback): + pass + def shutdown(self): + pass diff --git a/src/fenrir-package/commands/commands/prev_line.py b/src/fenrir-package/commands/commands/prev_line.py index 9bfdeb03..ad178fe2 100644 --- a/src/fenrir-package/commands/commands/prev_line.py +++ b/src/fenrir-package/commands/commands/prev_line.py @@ -1,20 +1,23 @@ #!/bin/python +from utils import line_utils class command(): def __init__(self): pass def run(self, environment): environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] - if environment['screenData']['newCursorReview']['y'] == -1: + if (environment['screenData']['newCursorReview']['y'] == -1) or \ + (environment['screenData']['newCursorReview']['x'] == -1): environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() - if environment['screenData']['newCursorReview']['y'] - 1 >= 0: - environment['screenData']['newCursorReview']['y'] = environment['screenData']['newCursorReview']['y'] - 1 - wrappedLines = environment['screenData']['newContentText'].split('\n') - if wrappedLines[environment['screenData']['newCursorReview']['y']].strip(" \t\n") == '': + + environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \ + line_utils.getPrevLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) + + if currLine.strip(" \t\n") == '': environment['runtime']['outputManager'].presentText(environment, "blank") else: - environment['runtime']['outputManager'].presentText(environment, wrappedLines[environment['screenData']['newCursorReview']['y']]) - return environment + environment['runtime']['outputManager'].presentText(environment, currLine) + return environment def setCallback(self, callback): pass def shutdown(self): diff --git a/src/fenrir-package/commands/commands/prev_word.py b/src/fenrir-package/commands/commands/prev_word.py index 1f16b3bd..e14983dc 100644 --- a/src/fenrir-package/commands/commands/prev_word.py +++ b/src/fenrir-package/commands/commands/prev_word.py @@ -1,43 +1,23 @@ #!/bin/python +from utils import word_utils class command(): def __init__(self): pass def run(self, environment): environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] - if environment['screenData']['newCursorReview']['y'] == -1: + if (environment['screenData']['newCursorReview']['y'] == -1) or \ + (environment['screenData']['newCursorReview']['x'] == -1): environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() - wrappedLines = environment['screenData']['newContentText'].split('\n') - currWord = '' - currY = environment['screenData']['newCursorReview']['y'] - currX = environment['screenData']['newCursorReview']['x'] - wordFound = False - while not wordFound: - if currX == 0: - if currY != 0: - currY -= 1 - else: - break - currX = len(wrappedLines[currY]) - 1 - else: - currX -= 1 - currLine = wrappedLines[currY].replace("\t"," ") - currX = currLine[:currX].rfind(" ") + 1 - if currX == -1: - currX = 0 - wordEnd = currLine[currX:].find(" ") + currX - if wordEnd == -1: - wordEnd = len(currLine) -1 - currWord = currLine[currX:wordEnd] - wordFound = currWord.strip(" \t\n") != '' - environment['screenData']['newCursorReview']['y'] = currY - environment['screenData']['newCursorReview']['x'] = currX - - if not wordFound: + + environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \ + word_utils.getPrevWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) + + if currWord.strip(" \t\n") == '': environment['runtime']['outputManager'].presentText(environment, "blank") else: environment['runtime']['outputManager'].presentText(environment, currWord) - return environment + return environment def setCallback(self, callback): pass def shutdown(self): diff --git a/src/fenrir-package/utils/char_utils.py b/src/fenrir-package/utils/char_utils.py new file mode 100644 index 00000000..10295180 --- /dev/null +++ b/src/fenrir-package/utils/char_utils.py @@ -0,0 +1,38 @@ +#!/bin/python + +def getPrevChar(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + if x - 1 < 0: + if y - 1 > 0: + y -= 1 + x = len(wrappedLines[y]) - 1 + else: + x -= 1 + currChar = wrappedLines[y][x] + return x, y, currChar + +def getCurrentChar(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + currChar = wrappedLines[currY][currX] + return currX, currY, currChar + +def getNextChar(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + if x + 1 == len(wrappedLines[y]): + if y + 1 < len(wrappedLines) - 1: + y += 1 + x = 0 + else: + x += 1 + currChar = wrappedLines[y][x] + return x, y, currChar diff --git a/src/fenrir-package/utils/chrys b/src/fenrir-package/utils/chrys deleted file mode 100644 index 8af20e24..00000000 --- a/src/fenrir-package/utils/chrys +++ /dev/null @@ -1,112 +0,0 @@ -def getPrevWord(currX,currY, currText): - if currText == '': - return -1, -1, '' - x, y, word = getCurrentWord(currX,currY,currText) - wrappedLines = currText.split('\n') - if (word == ''): - return currX, currY, '' - while True: - if x < 2: - if y != 0: - y -= 1 - else: - return currX, currY, '' - x = len(wrappedLines[y]) - 1 - else: - x -= 1 - if wrappedLines[y] != '': - break - x, y, word = getCurrentWord(x, y, currText) - if word == '': - return currX, currY, '' - return x, y, word - -def getCurrentWord(currX,currY, currText): - if currText == '': - return -1, -1, '' - x = currX - y = currY - wrappedLines = currText.split('\n') - wordFound = False - currWord = '' - currLine = wrappedLines[y].replace("\t"," ") - if currLine[x] == ' ' and x > 1: - x = x - 2 - while not wordFound: - x = currLine[:x].rfind(" ") - if x == -1: - x = 0 - else: - x += 1 - wordEnd = currLine[x + 1:].find(" ") - if wordEnd == -1: - wordEnd = len(currLine) - else: - wordEnd += x + 1 - currWord = currLine[x:wordEnd] - wordFound = currWord.strip(" \t\n") != '' - if wordFound: - break - if x == 0: - if y != 0: - y -= 1 - currLine = wrappedLines[y].replace("\t"," ") - else: - return currX, currY, '' - x = len(wrappedLines[y]) - 1 - else: - x -= 1 - return x, y, currWord - -def getNextWord(currX,currY, currText): - if currText == '': - return -1, -1, '' - x = currX - y = currY - wrappedLines = currText.split('\n') - wordFound = False - currWord = '' - currLine = wrappedLines[y].replace("\t"," ") - while not wordFound: - xtmp = 0 - if x + 1 >= len(currLine): - if y < len(wrappedLines): - y += 1 - currLine = wrappedLines[y].replace("\t"," ") - else: - return currX, currY, '' - x = 0 - else: - x += 1 - xtmp = x - x = currLine[x:].find(" ") - if x == -1: - x = len(currLine) - continue - else: - if xtmp <> 0: - xtmp += 1 - x += xtmp - if x + 1 < len(currLine): - wordEnd = currLine[x + 1:].find(" ") - else: - wordEnd = -1 - if wordEnd == -1: - wordEnd = len(currLine) - else: - wordEnd += x + 1 - if wordEnd >= len(currLine) and y + 1 >= len(wrappedLines): - return currX, currY, '' - currWord = currLine[x:wordEnd] - wordFound = currWord.strip(" \t\n") != '' - if not wordFound: - x = wordEnd - return x, y, currWord - -currText = " das ist ein test\ntest das\ntesttest\n\ntest" -currY = 0 -currX = 4 -currX, currY, word = getCurrentWord(currX,currY,currText) -#currX, currY, word = getPrevWord(currX,currY,currText) -#currX, currY, word = getNextWord(currX,currY,currText) -print(currX, currY, word) diff --git a/src/fenrir-package/utils/line_utils.py b/src/fenrir-package/utils/line_utils.py new file mode 100644 index 00000000..6a60a672 --- /dev/null +++ b/src/fenrir-package/utils/line_utils.py @@ -0,0 +1,35 @@ +#!/bin/python + +def getPrevLine(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + if y - 1 >= 0: + y -= 1 + x = 0 + currLine = wrappedLines[y] + return x, y, currLine + +def getCurrentLine(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + x = 0 + currLine = wrappedLines[y] + return x, y, currLine + +def getNextLine(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + if y + 1 < len(wrappedLines): + y += 1 + x = 0 + currLine = wrappedLines[y] + return x, y, currLine diff --git a/src/fenrir-package/utils/word_utils.py b/src/fenrir-package/utils/word_utils.py index 8f182230..9ce88d9e 100644 --- a/src/fenrir-package/utils/word_utils.py +++ b/src/fenrir-package/utils/word_utils.py @@ -3,9 +3,9 @@ def getPrevWord(currX,currY, currText): if currText == '': return -1, -1, '' - x, y, word = getCurrentWord(currX,currY,currText) + x, y, currWord = getCurrentWord(currX,currY,currText) wrappedLines = currText.split('\n') - if (word == ''): + if (currWord == ''): return currX, currY, '' while True: if x < 2: @@ -18,10 +18,10 @@ def getPrevWord(currX,currY, currText): x -= 1 if wrappedLines[y] != '': break - x, y, word = getCurrentWord(x, y, currText) - if word == '': + x, y, currWord = getCurrentWord(x, y, currText) + if currWord == '': return currX, currY, '' - return x, y, word + return x, y, currWord def getCurrentWord(currX,currY, currText): if currText == '': @@ -86,7 +86,7 @@ def getNextWord(currX,currY, currText): x = len(currLine) continue else: - if xtmp <> 0: + if xtmp != 0: xtmp += 1 x += xtmp if x + 1 < len(currLine):