Fix IRC incoming announcements and add focus.tui default
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributors.
|
||||
|
||||
import difflib
|
||||
import time
|
||||
from fenrirscreenreader.core.i18n import _
|
||||
|
||||
@@ -111,6 +112,71 @@ class command:
|
||||
|
||||
return False
|
||||
|
||||
def _normalize_line(self, line):
|
||||
return " ".join(line.split())
|
||||
|
||||
def _is_subsequence(self, subset_lines, source_lines):
|
||||
subset_index = 0
|
||||
for source_line in source_lines:
|
||||
if source_line == subset_lines[subset_index]:
|
||||
subset_index += 1
|
||||
if subset_index == len(subset_lines):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _prefer_inserted_lower_screen_text(self, delta_text):
|
||||
delta_lines = [
|
||||
line for line in delta_text.splitlines() if line.strip() != ""
|
||||
]
|
||||
if len(delta_lines) < 2:
|
||||
return delta_text
|
||||
|
||||
old_lines = self.env["screen"]["old_content_text"].split("\n")
|
||||
new_lines = self.env["screen"]["new_content_text"].split("\n")
|
||||
if len(old_lines) != len(new_lines) or len(new_lines) < 4:
|
||||
return delta_text
|
||||
|
||||
normalized_old_lines = [
|
||||
self._normalize_line(line) for line in old_lines
|
||||
]
|
||||
normalized_new_lines = [
|
||||
self._normalize_line(line) for line in new_lines
|
||||
]
|
||||
matcher = difflib.SequenceMatcher(
|
||||
None, normalized_old_lines, normalized_new_lines, autojunk=False
|
||||
)
|
||||
|
||||
top_lines_changed = False
|
||||
inserted_lines = []
|
||||
lower_screen_start = max(2, len(new_lines) // 2)
|
||||
|
||||
for tag, old_start, old_end, new_start, new_end in matcher.get_opcodes():
|
||||
if tag in {"replace", "delete"} and old_start < 2:
|
||||
top_lines_changed = True
|
||||
if tag != "insert" or new_start < lower_screen_start:
|
||||
continue
|
||||
inserted_lines.extend(
|
||||
line for line in new_lines[new_start:new_end] if line.strip() != ""
|
||||
)
|
||||
|
||||
if not top_lines_changed or not inserted_lines:
|
||||
return delta_text
|
||||
|
||||
normalized_delta_lines = [
|
||||
self._normalize_line(line) for line in delta_lines
|
||||
]
|
||||
normalized_inserted_lines = [
|
||||
self._normalize_line(line) for line in inserted_lines
|
||||
]
|
||||
if not self._is_subsequence(
|
||||
normalized_inserted_lines, normalized_delta_lines
|
||||
):
|
||||
return delta_text
|
||||
if normalized_delta_lines == normalized_inserted_lines:
|
||||
return delta_text
|
||||
|
||||
return "\n".join(inserted_lines)
|
||||
|
||||
def run(self):
|
||||
if not self.env["runtime"]["SettingsManager"].get_setting_as_bool(
|
||||
"speech", "auto_read_incoming"
|
||||
@@ -169,6 +235,7 @@ class command:
|
||||
return
|
||||
|
||||
# print(x_move, y_move, len(self.env['screen']['new_delta']), len(self.env['screen']['newNegativeDelta']))
|
||||
delta_text = self._prefer_inserted_lower_screen_text(delta_text)
|
||||
self.env["runtime"]["OutputManager"].present_text(
|
||||
delta_text, interrupt=False, flush=False
|
||||
)
|
||||
|
||||
@@ -81,6 +81,7 @@ settings_data = {
|
||||
"focus": {
|
||||
"cursor": True,
|
||||
"highlight": False,
|
||||
"tui": False,
|
||||
},
|
||||
"remote": {
|
||||
"enabled": True,
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributors.
|
||||
|
||||
version = "2026.03.04"
|
||||
version = "2026.03.25"
|
||||
code_name = "testing"
|
||||
|
||||
Reference in New Issue
Block a user