polish clipboard handling, clean ups, more mark functions

This commit is contained in:
chrys 2016-08-25 01:42:46 +02:00
parent 41caeed747
commit acd10812c6
14 changed files with 41 additions and 45 deletions

View File

@ -1,11 +1,13 @@
#!/bin/python #!/bin/python
from utils import mark_utils try:
from utils import mark_utils
except Exception as e:
print(e)
class command(): class command():
def __init__(self): def __init__(self):
pass pass
def run(self, environment): def run(self, environment):
print('run')
if (environment['commandBuffer']['Marks']['1'] == None) or \ if (environment['commandBuffer']['Marks']['1'] == None) or \
(environment['commandBuffer']['Marks']['2'] == None): (environment['commandBuffer']['Marks']['2'] == None):
environment['runtime']['outputManager'].presentText(environment, "two marks needed", interrupt=True) environment['runtime']['outputManager'].presentText(environment, "two marks needed", interrupt=True)
@ -17,12 +19,15 @@ class command():
if environment['commandBuffer']['Marks']['3'] != None: if environment['commandBuffer']['Marks']['3'] != None:
endMark = environment['commandBuffer']['Marks']['3'].copy() endMark = environment['commandBuffer']['Marks']['3'].copy()
marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'].split('\n')) marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'])
environment['commandBuffer']['clipboard'] = [marked] + environment['commandBuffer']['clipboard'][:9] environment['commandBuffer']['clipboard'] = [marked] + environment['commandBuffer']['clipboard'][:9]
environment['commandBuffer']['currClipboard'] = 0 environment['commandBuffer']['currClipboard'] = 0
environment['commandBuffer']['Marks']['1'] = None
environment['commandBuffer']['Marks']['2'] = None
environment['commandBuffer']['Marks']['3'] = None
if marked.strip(" \t\n") == '': if marked.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, marked, interrupt=True) environment['runtime']['outputManager'].presentText(environment, marked, interrupt=True)

View File

@ -12,7 +12,7 @@ class command():
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \ environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \
char_utils.getCurrentChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) char_utils.getCurrentChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
if currChar.strip(" \t\n") == '': if currChar.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank" ,interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank" ,interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, currChar ,interrupt=True) environment['runtime']['outputManager'].presentText(environment, currChar ,interrupt=True)

View File

@ -12,7 +12,7 @@ class command():
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \ environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \
line_utils.getCurrentLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) line_utils.getCurrentLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
if currLine.strip(" \t\n") == '': if currLine.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True) environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True)

View File

@ -12,7 +12,7 @@ class command():
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \ environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \
word_utils.getCurrentWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) word_utils.getCurrentWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
if currWord.strip(" \t\n") == '': if currWord.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True) environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True)

View File

@ -4,10 +4,7 @@ class command():
def __init__(self): def __init__(self):
pass pass
def run(self, environment): def run(self, environment):
if environment['screenData']['newDelta'].strip(" \t\n") == '': environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], interrupt=True)
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
else:
environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], interrupt=True)
return environment return environment
def setCallback(self, callback): def setCallback(self, callback):
pass pass

View File

@ -15,7 +15,7 @@ class command():
with open("/dev/tty" + environment['screenData']['newTTY'], 'w') as fd: with open("/dev/tty" + environment['screenData']['newTTY'], 'w') as fd:
for c in environment['commandBuffer']['clipboard'][currClipboard]: for c in environment['commandBuffer']['clipboard'][currClipboard]:
fcntl.ioctl(fd, termios.TIOCSTI, c) fcntl.ioctl(fd, termios.TIOCSTI, c)
time.sleep(0.01) time.sleep(0.02)
return environment return environment
def setCallback(self, callback): def setCallback(self, callback):
pass pass

View File

@ -16,9 +16,9 @@ class command():
if environment['commandBuffer']['Marks']['3'] != None: if environment['commandBuffer']['Marks']['3'] != None:
endMark = environment['commandBuffer']['Marks']['3'].copy() endMark = environment['commandBuffer']['Marks']['3'].copy()
marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'].split('\n')) marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'])
if marked.strip(" \t\n") == '': if marked.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, marked, interrupt=True) environment['runtime']['outputManager'].presentText(environment, marked, interrupt=True)

View File

@ -12,7 +12,7 @@ class command():
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \ environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \
char_utils.getNextChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) char_utils.getNextChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
if currChar.strip(" \t\n") == '': if currChar.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, currChar, interrupt=True) environment['runtime']['outputManager'].presentText(environment, currChar, interrupt=True)

View File

@ -12,7 +12,7 @@ class command():
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \ environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \
line_utils.getNextLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) line_utils.getNextLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
if currLine.strip(" \t\n") == '': if currLine.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True) environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True)

View File

@ -12,7 +12,7 @@ class command():
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \ environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \
word_utils.getNextWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) word_utils.getNextWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
if currWord.strip(" \t\n") == '': if currWord.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True) environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True)

View File

@ -12,7 +12,7 @@ class command():
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \ environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \
char_utils.getPrevChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) char_utils.getPrevChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
if currChar.strip(" \t\n") == '': if currChar.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, currChar, interrupt=True) environment['runtime']['outputManager'].presentText(environment, currChar, interrupt=True)

View File

@ -12,7 +12,7 @@ class command():
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \ environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \
line_utils.getPrevLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) line_utils.getPrevLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
if currLine.strip(" \t\n") == '': if currLine.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True) environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True)

View File

@ -12,7 +12,7 @@ class command():
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \ environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \
word_utils.getPrevWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText']) word_utils.getPrevWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
if currWord.strip(" \t\n") == '': if currWord.strip() == '':
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True) environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
else: else:
environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True) environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True)

View File

@ -3,12 +3,10 @@
def getTextBetweenMarks(firstMark, secondMark, inText): def getTextBetweenMarks(firstMark, secondMark, inText):
if inText == None: if inText == None:
return '' return ''
if isinstance(inText, list): if not isinstance(inText, list):
inText = inText.split('\n') inText = inText.split('\n')
if len(inText) < 1: if len(inText) < 1:
return '' return ''
if inText == '':
return ''
if firstMark == None: if firstMark == None:
return '' return ''
if secondMark == None: if secondMark == None:
@ -19,30 +17,30 @@ def getTextBetweenMarks(firstMark, secondMark, inText):
else: else:
endMark = firstMark.copy() endMark = firstMark.copy()
startMark = secondMark.copy() startMark = secondMark.copy()
currX = startMark['x']
currY = startMark['y']
textPart = '' textPart = ''
while currY <= endMark['y'] and currY <= len(inText): if startMark['y'] == endMark['y']:
if startMark['y'] == endMark['y']: textPart += inText[startMark['y']][startMark['x']:endMark['x'] + 1]
textPart += inText[currY][currX:endMark['x'] + 1] else:
else: currY = startMark['y']
while currY <= endMark['y']:
if currY < endMark['y']: if currY < endMark['y']:
textPart += inText[currY][currX:] if currY == startMark['y']:
if len(textPart) - len(textPart[::-1].strip()) > 0: textPart += inText[currY][startMark['x']:]
textPart = textPart[:len(textPart[::-1].strip())] + "\n" else:
textPart += inText[currY]
if len(inText[currY].strip()) != 0:
if len(textPart) - len(textPart[::-1].strip()) > 0:
textPart = textPart[:len(textPart[::-1].strip())] + "\n"
else:
textPart += '\n'
else: else:
textPart += inText[currY][:currX + 1] textPart += inText[currY][:endMark['x'] + 1]
currX = 0 currY += 1
currY += 1
return textPart return textPart
def getTextBeforeMark(mark, inText): def getTextBeforeMark(mark, inText):
if inText == None: if inText == None:
return '' return ''
if isinstance(inText, list):
inText = inText.split('\n')
if len(inText) < 1:
return ''
if mark == None: if mark == None:
return '' return ''
return getTextBetweenMarks({'x':0,'y':0}, mark, inText) return getTextBetweenMarks({'x':0,'y':0}, mark, inText)
@ -50,10 +48,6 @@ def getTextBeforeMark(mark, inText):
def getTextAfterMark(mark, inText): def getTextAfterMark(mark, inText):
if inText == None: if inText == None:
return '' return ''
if isinstance(inText, list):
inText = inText.split('\n')
if len(inText) < 1:
return ''
if mark == None: if mark == None:
return '' return ''
return getTextBetweenMarks(mark, {'x':len(inText[0])-1,'y':len(inText)-1}, inText) return getTextBetweenMarks(mark, {'x':len(inText[0])-1,'y':len(inText)-1}, inText)