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): def run(self):
cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() 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']['settingsManager'].getSetting('general', 'attributeFormatString')
attributeFormatString = self.env['runtime']['attributeManager'].formatAttributes(attributes, attributeFormatString) attributeFormatString = self.env['runtime']['attributeManager'].formatAttributes(attributes, attributeFormatString)

View File

@ -18,7 +18,8 @@ class command():
def run(self): def run(self):
if not self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'highlight'): if not self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'highlight'):
return 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): def setCallback(self, callback):
pass pass

View File

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

View File

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