port onInput to new parameters and modolarize some stuff
This commit is contained in:
parent
74aee822a3
commit
6668832eda
@ -5,6 +5,7 @@
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
|
||||
from core import debug
|
||||
from utils import char_utils
|
||||
|
||||
class command():
|
||||
def __init__(self):
|
||||
@ -17,20 +18,22 @@ class command():
|
||||
return ''
|
||||
|
||||
def run(self):
|
||||
if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']:
|
||||
if self.environment['runtime']['screenManager'].isScreenChange():
|
||||
return
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
# detect an change on the screen, we just want to cursor arround, so no change should appear
|
||||
if self.env['screenData']['newDelta'] != '':
|
||||
if self.environment['runtime']['screenManager'].isDelta():
|
||||
return
|
||||
if self.env['screenData']['newNegativeDelta'] != '':
|
||||
return
|
||||
if self.environment['runtime']['screenManager'].isNegativeDelta():
|
||||
return
|
||||
# is a vertical change?
|
||||
if self.environment['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
return
|
||||
# is it a horizontal change?
|
||||
if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y'] or\
|
||||
self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']:
|
||||
if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove():
|
||||
return
|
||||
currChar = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']][self.env['screenData']['newCursor']['x']]
|
||||
x, y, currChar, endOfScreen = char_utils.getCurrentChar(self.env['screenData']['newCursor']['x'], self.env['screenData']['newCursor']['y'], self.env['screenData']['newContentText'])
|
||||
if not currChar.isspace():
|
||||
self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True)
|
||||
def setCallback(self, callback):
|
||||
|
@ -25,7 +25,7 @@ class command():
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
# is there any change?
|
||||
if self.env['screenData']['newDelta'] == '':
|
||||
if not self.environment['runtime']['screenManager'].isDelta():
|
||||
return
|
||||
# big changes are no char (but the value is bigger than one maybe the differ needs longer than you can type, so a little strange random buffer for now)
|
||||
if len(self.env['screenData']['newDelta']) > 3:
|
||||
|
@ -5,6 +5,7 @@
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
|
||||
from core import debug
|
||||
from utils import line_utils
|
||||
|
||||
class command():
|
||||
def __init__(self):
|
||||
@ -19,15 +20,16 @@ class command():
|
||||
def run(self):
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']:
|
||||
if self.environment['runtime']['screenManager'].isScreenChange():
|
||||
return
|
||||
if self.env['screenData']['newDelta'] != self.env['screenData']['oldDelta']:
|
||||
if self.environment['runtime']['screenManager'].isDelta():
|
||||
return
|
||||
if self.env['screenData']['newCursor']['y'] == self.env['screenData']['oldCursor']['y']:
|
||||
return
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
currLine = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']]
|
||||
# is a vertical change?
|
||||
if not self.environment['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
return
|
||||
|
||||
x, y, currLine, endOfScreen = line_utils.getCurrentLine(self.env['screenData']['newCursor']['x'], self.env['screenData']['newCursor']['y'], self.env['screenData']['newContentText'])
|
||||
|
||||
if currLine.isspace():
|
||||
self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True)
|
||||
else:
|
||||
|
@ -18,27 +18,29 @@ class command():
|
||||
return 'No Description found'
|
||||
|
||||
def run(self):
|
||||
# first place could not be the end of a word
|
||||
if self.env['screenData']['newCursor']['x'] == 0:
|
||||
return
|
||||
# is it enabled?
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'wordEcho'):
|
||||
return
|
||||
|
||||
# just when cursor move worddetection is needed
|
||||
if self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']:
|
||||
return
|
||||
if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove():
|
||||
return
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
# for now no new line
|
||||
if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']:
|
||||
return
|
||||
if self.environment['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
return
|
||||
# is there a delta bigger than keyecho?
|
||||
if len(self.env['screenData']['newDelta']) > 1:
|
||||
return
|
||||
|
||||
# first place could not be the end of a word
|
||||
if self.env['screenData']['newCursor']['x'] == 0:
|
||||
return
|
||||
|
||||
|
||||
# get the word
|
||||
newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']]
|
||||
x, y, currWord = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent)
|
||||
x, y, currWord, endOfScreen = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent)
|
||||
# was this a typed word?
|
||||
if self.env['screenData']['newDelta'] != '':
|
||||
if not(newContent[self.env['screenData']['oldCursor']['x']].strip(" \t\n") == '' and x != self.env['screenData']['oldCursor']['x']):
|
||||
|
@ -45,23 +45,25 @@ class command():
|
||||
return
|
||||
|
||||
# just when cursor move worddetection is needed
|
||||
if self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']:
|
||||
return
|
||||
if not self.environment['runtime']['cursorManager'].isCursorHorizontalMove():
|
||||
return
|
||||
|
||||
# for now no new line
|
||||
if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']:
|
||||
return
|
||||
if self.environment['runtime']['cursorManager'].isCursorVerticalMove():
|
||||
return
|
||||
# more than a keyecho?
|
||||
if len(self.env['screenData']['newDelta']) > 1:
|
||||
return
|
||||
if self.env['screenData']['newNegativeDelta'] != '':
|
||||
return
|
||||
# deletion
|
||||
if self.environment['runtime']['screenManager'].isNegativeDelta():
|
||||
return
|
||||
# first place could not be the end of a word
|
||||
if self.env['screenData']['newCursor']['x'] == 0:
|
||||
return
|
||||
|
||||
# get the word
|
||||
# get the word (just for speedup only look at current line
|
||||
newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']]
|
||||
x, y, currWord = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent)
|
||||
x, y, currWord, endOfScreen = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent)
|
||||
# was this a typed word?
|
||||
if self.env['screenData']['newDelta'] != '':
|
||||
if not(newContent[self.env['screenData']['oldCursor']['x']] in string.whitespace + '!"#$%&()*+,-./:;<=>?@[\\]^_{|}~' and x != self.env['screenData']['oldCursor']['x']):
|
||||
|
@ -25,14 +25,13 @@ class command():
|
||||
return
|
||||
|
||||
# More than just a deletion happend
|
||||
if self.env['screenData']['newDelta'].strip() != '':
|
||||
if self.env['screenData']['newDelta'] != self.env['screenData']['oldDelta']:
|
||||
return
|
||||
if self.environment['runtime']['screenManager'].isDelta():
|
||||
return
|
||||
# no deletion
|
||||
if not self.environment['runtime']['screenManager'].isNegativeDelta():
|
||||
return
|
||||
if self.env['runtime']['inputManager'].noKeyPressed():
|
||||
return
|
||||
# No deletion
|
||||
if self.env['screenData']['newNegativeDelta'] == '':
|
||||
return
|
||||
# too much for a single backspace...
|
||||
if len(self.env['screenData']['newNegativeDelta']) >= 2:
|
||||
return
|
||||
|
@ -47,7 +47,13 @@ class cursorManager():
|
||||
return
|
||||
self.env['screenData']['oldCursorReview'] = None
|
||||
self.env['screenData']['newCursorReview'] = None
|
||||
|
||||
def isCursorHorizontalMove(self):
|
||||
return self.env['screenData']['newCursor']['x'] != self.env['screenData']['oldCursor']['x']
|
||||
|
||||
def isCursorVerticalMove(self):
|
||||
return self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']
|
||||
|
||||
|
||||
def isReviewMode(self):
|
||||
return self.env['screenData']['newCursorReview'] != None
|
||||
def enterReviewModeCurrTextCursor(self, overwrite=False):
|
||||
|
@ -44,7 +44,10 @@ class screenManager():
|
||||
if not self.env['screenData']['oldTTY']:
|
||||
return False
|
||||
return self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']
|
||||
|
||||
def isDelta(self):
|
||||
return self.env['screenData']['newDelta'] != ''
|
||||
def isNegativeDelta(self):
|
||||
return self.env['screenData']['newNegativeDelta'] != ''
|
||||
def getWindowAreaInText(self, text):
|
||||
if not self.env['runtime']['cursorManager'].isApplicationWindowSet():
|
||||
return text
|
||||
|
@ -27,7 +27,7 @@ def getPrevChar(currX,currY, currText):
|
||||
def getCurrentChar(currX,currY, currText):
|
||||
endOfScreen = False
|
||||
if currText == '':
|
||||
return -1, -1, ''
|
||||
return -1, -1, '', endOfScreen
|
||||
wrappedLines = currText.split('\n')
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar, endOfScreen
|
||||
@ -39,7 +39,9 @@ def getUpChar(currX,currY, currText):
|
||||
wrappedLines = currText.split('\n')
|
||||
currY -= 1
|
||||
if currY < 0:
|
||||
currY = 0
|
||||
currY = 0
|
||||
else:
|
||||
endOfScreen = True
|
||||
currChar = wrappedLines[currY][currX]
|
||||
return currX, currY, currChar, endOfScreen
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user