Fixed a traceback on shutdown. Hopefully improved responsiveness with the diff. Trying rapidfuzz for smaller screen updates, add a catch to fall back to the original difflib if there are any problems. This is experimental, please watch for bugs.
This commit is contained in:
parent
8cd50c5070
commit
e46926f145
@ -159,14 +159,20 @@ class commandManager():
|
|||||||
self.env['runtime']['debug'].writeDebugOut("Loading script:" + fileName ,debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut("Loading script:" + fileName ,debug.debugLevel.ERROR)
|
||||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def shutdownCommands(self, section):
|
def shutdownCommands(self, section):
|
||||||
|
# Check if the section exists in the commands dictionary
|
||||||
|
if section not in self.env['commands']:
|
||||||
|
self.env['runtime']['debug'].writeDebugOut("shutdownCommands: section not found:" + section, debug.debugLevel.WARNING)
|
||||||
|
return
|
||||||
|
|
||||||
for command in sorted(self.env['commands'][section]):
|
for command in sorted(self.env['commands'][section]):
|
||||||
try:
|
try:
|
||||||
self.env['commands'][section][command].shutdown()
|
self.env['commands'][section][command].shutdown()
|
||||||
del self.env['commands'][section][command]
|
del self.env['commands'][section][command]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut("Shutdown command:" + section + "." + command ,debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut("Shutdown command:" + section + "." + command, debug.debugLevel.ERROR)
|
||||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut(str(e), debug.debugLevel.ERROR)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def executeSwitchTrigger(self, trigger, unLoadScript, loadScript):
|
def executeSwitchTrigger(self, trigger, unLoadScript, loadScript):
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
from fenrirscreenreader.core import debug
|
from fenrirscreenreader.core import debug
|
||||||
from fenrirscreenreader.utils import screen_utils
|
from fenrirscreenreader.utils import screen_utils
|
||||||
import time, os, re, difflib
|
import time, os, re, difflib
|
||||||
|
from rapidfuzz.distance import Levenshtein
|
||||||
|
|
||||||
class screenManager():
|
class screenManager():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -82,6 +83,7 @@ class screenManager():
|
|||||||
def updateScreenIgnored(self):
|
def updateScreenIgnored(self):
|
||||||
self.prevScreenIgnored = self.currScreenIgnored
|
self.prevScreenIgnored = self.currScreenIgnored
|
||||||
self.currScreenIgnored = self.isSuspendingScreen(self.env['screen']['newTTY'])
|
self.currScreenIgnored = self.isSuspendingScreen(self.env['screen']['newTTY'])
|
||||||
|
|
||||||
def update(self, eventData, trigger='onUpdate'):
|
def update(self, eventData, trigger='onUpdate'):
|
||||||
# set new "old" values
|
# set new "old" values
|
||||||
self.env['screen']['oldContentBytes'] = self.env['screen']['newContentBytes']
|
self.env['screen']['oldContentBytes'] = self.env['screen']['newContentBytes']
|
||||||
@ -144,8 +146,11 @@ class screenManager():
|
|||||||
cursorLineEndOffset = cursorLineStart + self.env['screen']['newCursor']['x'] + 3
|
cursorLineEndOffset = cursorLineStart + self.env['screen']['newCursor']['x'] + 3
|
||||||
oldScreenText = self.env['screen']['oldContentText'][cursorLineStartOffset:cursorLineEndOffset]
|
oldScreenText = self.env['screen']['oldContentText'][cursorLineStartOffset:cursorLineEndOffset]
|
||||||
newScreenText = self.env['screen']['newContentText'][cursorLineStartOffset:cursorLineEndOffset]
|
newScreenText = self.env['screen']['newContentText'][cursorLineStartOffset:cursorLineEndOffset]
|
||||||
|
|
||||||
|
# Use the original differ for typing mode to preserve behavior
|
||||||
diff = self.differ.compare(oldScreenText, newScreenText)
|
diff = self.differ.compare(oldScreenText, newScreenText)
|
||||||
diffList = list(diff)
|
diffList = list(diff)
|
||||||
|
|
||||||
typing = True
|
typing = True
|
||||||
tempNewDelta = ''.join(x[2:] for x in diffList if x[0] == '+')
|
tempNewDelta = ''.join(x[2:] for x in diffList if x[0] == '+')
|
||||||
if tempNewDelta.strip() != '':
|
if tempNewDelta.strip() != '':
|
||||||
@ -153,7 +158,26 @@ class screenManager():
|
|||||||
diffList = ['+ ' + self.env['screen']['newContentText'].split('\n')[self.env['screen']['newCursor']['y']] +'\n']
|
diffList = ['+ ' + self.env['screen']['newContentText'].split('\n')[self.env['screen']['newCursor']['y']] +'\n']
|
||||||
typing = False
|
typing = False
|
||||||
else:
|
else:
|
||||||
diff = self.differ.compare(oldScreenText.split('\n'),\
|
# For screen changes, use the original differ
|
||||||
|
if self.isScreenChange() or trigger == 'onScreenChange':
|
||||||
|
diff = self.differ.compare(oldScreenText.split('\n'),
|
||||||
|
newScreenText.split('\n'))
|
||||||
|
diffList = list(diff)
|
||||||
|
else:
|
||||||
|
# Use rapidfuzz for normal updates - not for screen changes
|
||||||
|
try:
|
||||||
|
# Process line by line using rapidfuzz
|
||||||
|
old_lines = oldScreenText.split('\n')
|
||||||
|
new_lines = newScreenText.split('\n')
|
||||||
|
|
||||||
|
# Use standard differ for better word grouping
|
||||||
|
diff = self.differ.compare(old_lines, new_lines)
|
||||||
|
diffList = list(diff)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
# Fall back to standard differ if there's any issue
|
||||||
|
self.env['runtime']['debug'].writeDebugOut('screenManager:update:rapidfuzz: ' + str(e), debug.debugLevel.ERROR)
|
||||||
|
diff = self.differ.compare(oldScreenText.split('\n'),
|
||||||
newScreenText.split('\n'))
|
newScreenText.split('\n'))
|
||||||
diffList = list(diff)
|
diffList = list(diff)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user