make attributeManager use

This commit is contained in:
chrys 2018-05-28 22:18:51 +02:00
parent 02624a692a
commit 366328dad7
4 changed files with 80 additions and 57 deletions

View File

@ -19,7 +19,8 @@ class command():
def run(self):
cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor()
attributes = self.env['screen']['newContentAttrib'][cursorPos['y']][cursorPos['x']]
attributes = self.env['runtime']['attributeManager'].getAttributeByXY( cursorPos['x'], cursorPos['y'])
attributeFormatString = self.env['runtime']['settingsManager'].getSetting('general', 'attributeFormatString')
attributeFormatString = self.env['runtime']['attributeManager'].formatAttributes(attributes, attributeFormatString)

View File

@ -18,7 +18,8 @@ class command():
def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'highlight'):
return
self.env['runtime']['outputManager'].presentText(self.env['screen']['newAttribDelta'], soundIcon='', interrupt=True, flush=False)
attributeDelta = self.env['runtime']['attributeManager'].getAttributeDelta()
self.env['runtime']['outputManager'].presentText(attributeDelta, soundIcon='', interrupt=True, flush=False)
def setCallback(self, callback):
pass

View File

@ -12,7 +12,6 @@ class attributeManager():
self.currAttributes = None
self.prevAttributes = None
self.currAttributeDelta = ''
self.prevAttributeDelta = ''
self.currAttributeCursor = None
self.prefAttributeCursor = None
self.setDefaultAttributes()
@ -20,25 +19,29 @@ class attributeManager():
self.env = environment
def shutdown(self):
pass
def isAttributeChange(self):
if not self.prevAttributes:
return False
return self.currAttributes != self.prevAttributes
def resetAttributeAll(self):
self.resetAttributeDelta()
self.resetAttributeCursor()
def getAttributeDelta(self):
return self.currAttributeDelta
def resetAttributeDelta(self):
self.currAttributeDelta = ''
self.prevAttributeDelta = ''
def updateAttributeDelta(self, currAttributeDelta):
self.prevAttributeDelta = self.currAttributeDelta
def setAttributeDelta(self, currAttributeDelta):
self.currAttributeDelta = currAttributeDelta
def resetAttributeCursor(self):
self.currAttributeCursor = None
self.prefAttributeCursor = None
def updateAttributeCursor(self, currAttributeCursor):
def setAttributeCursor(self, currAttributeCursor):
self.prefAttributeCursor = self.currAttributeCursor
self.currAttributeCursor = currAttributeCursor
def resetAttributeData(self, currAttributes):
self.currAttributeCursor = currAttributeCursor.copy()
def resetAttributes(self, currAttributes):
self.prevAttributes = None
self.currAttributes = currAttributes
def updateAttributeData(self, currAttributes):
def setAttributes(self, currAttributes):
self.prevAttributes = self.currAttributes
self.currAttributes = currAttributes.copy()
def getAttributeByXY(self, x, y):
@ -46,14 +49,21 @@ class attributeManager():
return None
if len(self.currAttributes) < y:
return None
if len(self.currAttributes[y]) < x:
if len(self.currAttributes[y]) < x - 1:
return None
return self.currAttributes[y][x]
try:
return self.currAttributes[y][x].copy()
except KeyError:
try:
return self.defaultAttributes[0]
except:
pass
return None
def setDefaultAttributes(self):
self.defaultAttributes = []
self.defaultAttributes.append((
'white', # fg
'black', # bg
'default', # fg
'default', # bg
False, # bold
False, # italics
False, # underscore
@ -64,8 +74,8 @@ class attributeManager():
'default' # fontfamily
)) #end attribute
self.defaultAttributes.append((
'default', # fg
'default', # bg
'white', # fg
'black', # bg
False, # bold
False, # italics
False, # underscore
@ -191,25 +201,26 @@ class attributeManager():
attributeFormatString = attributeFormatString.replace('fenrirFont', _('default'))
return attributeFormatString
def trackHighlights(self, oldAttr, newAttr, text):
def trackHighlights(self):
result = ''
currCursor = None
# screen change
if oldAttr == None:
if self.prevAttributes == None:
return result, currCursor
# no change
if oldAttr == newAttr:
if self.prevAttributes == self.currAttributes:
return result, currCursor
# error case
if newAttr == None:
if self.currAttributes == None:
return result, currCursor
# special case for pty if not text exists.
if len(newAttr) == 0:
if len(self.currAttributes) == 0:
return result, currCursor
text = self.env['runtime']['screenManager'].getScreenText()
textLines = text.split('\n')
if len(textLines) != len(newAttr):
if len(textLines) != len(self.currAttributes):
return result, currCursor
#print(len(textLines), len(newAttr))
#background = []
@ -240,11 +251,11 @@ class attributeManager():
except Exception as e:
print(e)
#background.append((7,7,0,0,0,0))
for line in range(len(oldAttr)):
if oldAttr[line] != newAttr[line]:
for column in range(len(oldAttr[line])):
if oldAttr[line][column] != newAttr[line][column]:
if not self.isDefaultAttribute(newAttr[line][column]):
for line in range(len(self.prevAttributes)):
if self.prevAttributes[line] != self.currAttributes[line]:
for column in range(len(self.prevAttributes[line])):
if self.prevAttributes[line][column] != self.currAttributes[line][column]:
if not self.isDefaultAttribute(self.currAttributes[line][column]):
if not currCursor:
currCursor = {'x': column, 'y': line}
result += textLines[line][column]

View File

@ -12,6 +12,8 @@ class screenManager():
def __init__(self):
self.currScreenIgnored = False
self.prevScreenIgnored = False
self.prevScreenText = ''
self.currScreenText = ''
def initialize(self, environment):
self.env = environment
self.env['runtime']['settingsManager'].loadDriver(\
@ -21,7 +23,14 @@ class screenManager():
self.getSessionInformation()
self.updateScreenIgnored()
self.updateScreenIgnored()
def resetScreenText(self, screenText):
self.prevScreenText = ''
self.currScreenText = screenText
def setScreenText(self, screenText):
self.prevScreenText = self.currScreenText
self.currScreenText = screenText
def getScreenText(self):
return self.currScreenText
def getCurrScreen(self):
try:
self.env['runtime']['screenDriver'].getCurrScreen()
@ -75,12 +84,8 @@ class screenManager():
# set new "old" values
self.env['screen']['oldContentBytes'] = self.env['screen']['newContentBytes']
self.env['screen']['oldContentText'] = self.env['screen']['newContentText']
self.env['screen']['oldContentAttrib'] = self.env['screen']['newContentAttrib']
self.env['screen']['oldCursor'] = self.env['screen']['newCursor'].copy()
if self.env['screen']['newCursorAttrib']:
self.env['screen']['oldCursorAttrib'] = self.env['screen']['newCursorAttrib'].copy()
self.env['screen']['oldDelta'] = self.env['screen']['newDelta']
self.env['screen']['oldAttribDelta'] = self.env['screen']['newAttribDelta']
self.env['screen']['oldNegativeDelta'] = self.env['screen']['newNegativeDelta']
self.env['screen']['newContentBytes'] = eventData['bytes']
@ -91,23 +96,25 @@ class screenManager():
self.env['screen']['newCursor']['y'] = int( eventData['textCursor']['y'])
self.env['screen']['newTTY'] = eventData['screen']
self.env['screen']['newContentText'] = eventData['text']
self.env['screen']['newContentAttrib'] = eventData['attributes']
# screen change
if self.env['screen']['newTTY'] != self.env['screen']['oldTTY']:
if self.isScreenChange():
self.env['screen']['oldContentBytes'] = b''
self.env['screen']['oldContentAttrib'] = None
self.resetScreenText(eventData['text'])
self.env['runtime']['attributeManager'].resetAttributes(eventData['attributes'])
self.env['runtime']['attributeManager'].resetAttributeCursor()
self.env['screen']['oldContentText'] = ''
self.env['screen']['oldCursor']['x'] = 0
self.env['screen']['oldCursor']['y'] = 0
self.env['screen']['oldDelta'] = ''
self.env['screen']['oldAttribDelta'] = ''
self.env['screen']['oldCursorAttrib'] = None
self.env['screen']['newCursorAttrib'] = None
self.env['screen']['oldNegativeDelta'] = ''
else:
self.setScreenText(eventData['text'])
self.env['runtime']['attributeManager'].setAttributes(eventData['attributes'])
# initialize current deltas
self.env['screen']['newNegativeDelta'] = ''
self.env['screen']['newDelta'] = ''
self.env['screen']['newAttribDelta'] = ''
self.env['runtime']['attributeManager'].resetAttributeDelta()
# changes on the screen
oldScreenText = re.sub(' +',' ',self.env['runtime']['screenManager'].getWindowAreaInText(self.env['screen']['oldContentText']))
@ -157,9 +164,12 @@ class screenManager():
# track highlighted
try:
if self.env['screen']['oldContentAttrib'] != self.env['screen']['newContentAttrib']:
if self.env['runtime']['attributeManager'].isAttributeChange():
if self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'highlight'):
self.env['screen']['newAttribDelta'], self.env['screen']['newCursorAttrib'] = self.env['runtime']['attributeManager'].trackHighlights(self.env['screen']['oldContentAttrib'], self.env['screen']['newContentAttrib'], self.env['screen']['newContentText'])
attributeDelta, attributeCursor = self.env['runtime']['attributeManager'].trackHighlights()
if attributeCursor:
self.env['runtime']['attributeManager'].setAttributeCursor(attributeCursor)
self.env['runtime']['attributeManager'].setAttributeDelta(attributeDelta)
except Exception as e:
print(e)
self.env['runtime']['debug'].writeDebugOut('screenManager:update:highlight: ' + str(e),debug.debugLevel.ERROR)