finish word wrappig, create util toolkit

This commit is contained in:
chrys
2016-07-22 16:57:43 +02:00
parent bd930a9692
commit 335ad9b71c
14 changed files with 206 additions and 234 deletions

View 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

View File

@ -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

View File

@ -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):

View 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

View File

@ -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

View File

@ -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):

View 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

View File

@ -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):

View File

@ -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):