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:
Storm Dragon 2025-02-26 17:02:25 -05:00
parent 8cd50c5070
commit e46926f145
2 changed files with 35 additions and 5 deletions

View File

@ -159,7 +159,13 @@ class commandManager():
self.env['runtime']['debug'].writeDebugOut("Loading script:" + fileName ,debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
continue
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]):
try:
self.env['commands'][section][command].shutdown()

View File

@ -7,6 +7,7 @@
from fenrirscreenreader.core import debug
from fenrirscreenreader.utils import screen_utils
import time, os, re, difflib
from rapidfuzz.distance import Levenshtein
class screenManager():
def __init__(self):
@ -82,6 +83,7 @@ class screenManager():
def updateScreenIgnored(self):
self.prevScreenIgnored = self.currScreenIgnored
self.currScreenIgnored = self.isSuspendingScreen(self.env['screen']['newTTY'])
def update(self, eventData, trigger='onUpdate'):
# set new "old" values
self.env['screen']['oldContentBytes'] = self.env['screen']['newContentBytes']
@ -144,8 +146,11 @@ class screenManager():
cursorLineEndOffset = cursorLineStart + self.env['screen']['newCursor']['x'] + 3
oldScreenText = self.env['screen']['oldContentText'][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)
diffList = list(diff)
typing = True
tempNewDelta = ''.join(x[2:] for x in diffList if x[0] == '+')
if tempNewDelta.strip() != '':
@ -153,7 +158,26 @@ class screenManager():
diffList = ['+ ' + self.env['screen']['newContentText'].split('\n')[self.env['screen']['newCursor']['y']] +'\n']
typing = False
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'))
diffList = list(diff)