finish word wrappig, create util toolkit
This commit is contained in:
parent
bd930a9692
commit
335ad9b71c
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
[sound]
|
[sound]
|
||||||
enabled=False,
|
enabled=False,
|
||||||
driver=sox
|
driver=sox
|
||||||
@ -29,4 +28,3 @@ wordEcho=True
|
|||||||
[general]
|
[general]
|
||||||
debugLevel=0
|
debugLevel=0
|
||||||
punctuationLevel=1
|
punctuationLevel=1
|
||||||
|
|
||||||
|
24
src/fenrir-package/commands/commands/curr_char.py
Normal file
24
src/fenrir-package/commands/commands/curr_char.py
Normal file
@ -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
|
@ -1,17 +1,22 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
from utils import line_utils
|
||||||
|
|
||||||
class command():
|
class command():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
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()
|
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")
|
environment['runtime']['outputManager'].presentText(environment, "blank")
|
||||||
else:
|
else:
|
||||||
environment['runtime']['outputManager'].presentText(environment, wrappedLines[environment['screenData']['newCursorReview']['y']])
|
environment['runtime']['outputManager'].presentText(environment, currLine)
|
||||||
return environment
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
@ -1,44 +1,23 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
from utils import word_utils
|
||||||
|
|
||||||
class command():
|
class command():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
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()
|
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
||||||
wrappedLines = environment['screenData']['newContentText'].split('\n')
|
|
||||||
currWord = ''
|
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \
|
||||||
currY = environment['screenData']['newCursorReview']['y']
|
word_utils.getCurrentWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||||
currX = environment['screenData']['newCursorReview']['x']
|
|
||||||
wordFound = False
|
if currWord.strip(" \t\n") == '':
|
||||||
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['runtime']['outputManager'].presentText(environment, "blank")
|
environment['runtime']['outputManager'].presentText(environment, "blank")
|
||||||
else:
|
else:
|
||||||
environment['runtime']['outputManager'].presentText(environment, currWord)
|
environment['runtime']['outputManager'].presentText(environment, currWord)
|
||||||
return environment
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
24
src/fenrir-package/commands/commands/next_char.py
Normal file
24
src/fenrir-package/commands/commands/next_char.py
Normal file
@ -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
|
@ -1,19 +1,22 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
from utils import line_utils
|
||||||
|
|
||||||
class command():
|
class command():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
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()
|
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
|
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \
|
||||||
wrappedLines = environment['screenData']['newContentText'].split('\n')
|
line_utils.getNextLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||||
if wrappedLines[environment['screenData']['newCursorReview']['y']].strip(" \t\n") == '':
|
|
||||||
|
if currLine.strip(" \t\n") == '':
|
||||||
environment['runtime']['outputManager'].presentText(environment, "blank")
|
environment['runtime']['outputManager'].presentText(environment, "blank")
|
||||||
else:
|
else:
|
||||||
environment['runtime']['outputManager'].presentText(environment, wrappedLines[environment['screenData']['newCursorReview']['y']])
|
environment['runtime']['outputManager'].presentText(environment, currLine)
|
||||||
return environment
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
@ -1,52 +1,23 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
from utils import word_utils
|
||||||
|
|
||||||
class command():
|
class command():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
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()
|
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
||||||
wrappedLines = environment['screenData']['newContentText'].split('\n')
|
|
||||||
currWord = ''
|
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \
|
||||||
currY = environment['screenData']['newCursorReview']['y']
|
word_utils.getNextWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||||
currX = environment['screenData']['newCursorReview']['x']
|
|
||||||
wordFound = False
|
if currWord.strip(" \t\n") == '':
|
||||||
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['runtime']['outputManager'].presentText(environment, "blank")
|
environment['runtime']['outputManager'].presentText(environment, "blank")
|
||||||
else:
|
else:
|
||||||
environment['runtime']['outputManager'].presentText(environment, currWord)
|
environment['runtime']['outputManager'].presentText(environment, currWord)
|
||||||
return environment
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
24
src/fenrir-package/commands/commands/prev_char.py
Normal file
24
src/fenrir-package/commands/commands/prev_char.py
Normal file
@ -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
|
@ -1,20 +1,23 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
from utils import line_utils
|
||||||
|
|
||||||
class command():
|
class command():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
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()
|
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
||||||
if environment['screenData']['newCursorReview']['y'] - 1 >= 0:
|
|
||||||
environment['screenData']['newCursorReview']['y'] = environment['screenData']['newCursorReview']['y'] - 1
|
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \
|
||||||
wrappedLines = environment['screenData']['newContentText'].split('\n')
|
line_utils.getPrevLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||||
if wrappedLines[environment['screenData']['newCursorReview']['y']].strip(" \t\n") == '':
|
|
||||||
|
if currLine.strip(" \t\n") == '':
|
||||||
environment['runtime']['outputManager'].presentText(environment, "blank")
|
environment['runtime']['outputManager'].presentText(environment, "blank")
|
||||||
else:
|
else:
|
||||||
environment['runtime']['outputManager'].presentText(environment, wrappedLines[environment['screenData']['newCursorReview']['y']])
|
environment['runtime']['outputManager'].presentText(environment, currLine)
|
||||||
return environment
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
@ -1,43 +1,23 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
from utils import word_utils
|
||||||
|
|
||||||
class command():
|
class command():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
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()
|
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
||||||
wrappedLines = environment['screenData']['newContentText'].split('\n')
|
|
||||||
currWord = ''
|
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \
|
||||||
currY = environment['screenData']['newCursorReview']['y']
|
word_utils.getPrevWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||||
currX = environment['screenData']['newCursorReview']['x']
|
|
||||||
wordFound = False
|
if currWord.strip(" \t\n") == '':
|
||||||
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['runtime']['outputManager'].presentText(environment, "blank")
|
environment['runtime']['outputManager'].presentText(environment, "blank")
|
||||||
else:
|
else:
|
||||||
environment['runtime']['outputManager'].presentText(environment, currWord)
|
environment['runtime']['outputManager'].presentText(environment, currWord)
|
||||||
return environment
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
38
src/fenrir-package/utils/char_utils.py
Normal file
38
src/fenrir-package/utils/char_utils.py
Normal file
@ -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
|
@ -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)
|
|
35
src/fenrir-package/utils/line_utils.py
Normal file
35
src/fenrir-package/utils/line_utils.py
Normal file
@ -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
|
@ -3,9 +3,9 @@
|
|||||||
def getPrevWord(currX,currY, currText):
|
def getPrevWord(currX,currY, currText):
|
||||||
if currText == '':
|
if currText == '':
|
||||||
return -1, -1, ''
|
return -1, -1, ''
|
||||||
x, y, word = getCurrentWord(currX,currY,currText)
|
x, y, currWord = getCurrentWord(currX,currY,currText)
|
||||||
wrappedLines = currText.split('\n')
|
wrappedLines = currText.split('\n')
|
||||||
if (word == ''):
|
if (currWord == ''):
|
||||||
return currX, currY, ''
|
return currX, currY, ''
|
||||||
while True:
|
while True:
|
||||||
if x < 2:
|
if x < 2:
|
||||||
@ -18,10 +18,10 @@ def getPrevWord(currX,currY, currText):
|
|||||||
x -= 1
|
x -= 1
|
||||||
if wrappedLines[y] != '':
|
if wrappedLines[y] != '':
|
||||||
break
|
break
|
||||||
x, y, word = getCurrentWord(x, y, currText)
|
x, y, currWord = getCurrentWord(x, y, currText)
|
||||||
if word == '':
|
if currWord == '':
|
||||||
return currX, currY, ''
|
return currX, currY, ''
|
||||||
return x, y, word
|
return x, y, currWord
|
||||||
|
|
||||||
def getCurrentWord(currX,currY, currText):
|
def getCurrentWord(currX,currY, currText):
|
||||||
if currText == '':
|
if currText == '':
|
||||||
@ -86,7 +86,7 @@ def getNextWord(currX,currY, currText):
|
|||||||
x = len(currLine)
|
x = len(currLine)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
if xtmp <> 0:
|
if xtmp != 0:
|
||||||
xtmp += 1
|
xtmp += 1
|
||||||
x += xtmp
|
x += xtmp
|
||||||
if x + 1 < len(currLine):
|
if x + 1 < len(currLine):
|
||||||
|
Loading…
Reference in New Issue
Block a user